UNPKG

@thi.ng/transducers-stats

Version:

Transducers for statistical / technical analysis

26 lines (25 loc) 519 B
class Deque { constructor(samples, pred) { this.samples = samples; this.pred = pred; } index = []; head() { return this.samples[this.index[0]]; } add(x) { const { index, samples, pred } = this; while (index.length && pred(samples[index[index.length - 1]], x)) { index.pop(); } index.push(samples.length - 1); } shift() { const { index } = this; if (index[0] === 0) index.shift(); for (let i = 0; i < index.length; i++) index[i]--; } } export { Deque };