UNPKG

@hyperlane-xyz/utils

Version:

General utilities and types for the Hyperlane network

21 lines 661 B
export function median(a) { const sorted = a.slice().sort(); const mid = Math.floor(sorted.length / 2); const median = sorted.length % 2 == 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid]; return median; } export function sum(a) { return a.reduce((acc, i) => acc + i); } export function mean(a) { return sum(a) / a.length; } export function stdDev(a) { const xbar = mean(a); const squaredDifferences = a.map((x) => Math.pow(x - xbar, 2)); return Math.sqrt(mean(squaredDifferences)); } export function randomInt(max, min = 0) { return Math.floor(Math.random() * (max - min)) + min; } //# sourceMappingURL=math.js.map