2020-05-24 11:29:30 +02:00
|
|
|
import { TransactionExtended } from '../interfaces';
|
|
|
|
|
|
|
|
export class Common {
|
|
|
|
static median(numbers: number[]) {
|
|
|
|
let medianNr = 0;
|
|
|
|
const numsLen = numbers.length;
|
|
|
|
if (numsLen % 2 === 0) {
|
|
|
|
medianNr = (numbers[numsLen / 2 - 1] + numbers[numsLen / 2]) / 2;
|
|
|
|
} else {
|
|
|
|
medianNr = numbers[(numsLen - 1) / 2];
|
|
|
|
}
|
|
|
|
return medianNr;
|
|
|
|
}
|
|
|
|
|
2020-05-26 06:02:12 +02:00
|
|
|
static getFeesInRange(transactions: TransactionExtended[], rangeLength: number, lastindex = 0) {
|
2020-05-24 11:29:30 +02:00
|
|
|
const arr = [transactions[transactions.length - 1].feePerVsize];
|
|
|
|
const chunk = 1 / (rangeLength - 1);
|
|
|
|
let itemsToAdd = rangeLength - 2;
|
|
|
|
|
|
|
|
while (itemsToAdd > 0) {
|
|
|
|
arr.push(transactions[Math.floor(transactions.length * chunk * itemsToAdd)].feePerVsize);
|
|
|
|
itemsToAdd--;
|
|
|
|
}
|
|
|
|
|
2020-05-26 06:02:12 +02:00
|
|
|
arr.push(transactions[lastindex].feePerVsize);
|
2020-05-24 11:29:30 +02:00
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
}
|