UNPKG

trading-signals

Version:

Technical indicators to run technical analysis with JavaScript / TypeScript.

20 lines 692 B
import { getMedian } from './getMedian.js'; export function getQuartile(values, q) { const sorted = [...values].sort((a, b) => a - b); const n = sorted.length; const medianIndex = Math.floor(n / 2); if (q === 0.25) { return getMedian(sorted.slice(0, medianIndex)); } else if (q === 0.75) { if (n % 2 === 0) { return getMedian(sorted.slice(medianIndex)); } return getMedian(sorted.slice(medianIndex + 1)); } const pos = (sorted.length - 1) * q; const base = Math.floor(pos); const rest = pos - base; return sorted[base] + (sorted[base + 1] - sorted[base]) * rest; } //# sourceMappingURL=getQuartile.js.map