UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

24 lines (22 loc) 671 B
import { toArray } from './toarray'; export function reduceRight(source, accumulator, ...seed) { const array = toArray(source); const hasSeed = seed.length === 1; let hasValue = false; let acc = seed[0]; for (let offset = array.length - 1; offset >= 0; offset--) { const item = array[offset]; if (hasValue || (hasValue = hasSeed)) { acc = accumulator(acc, item, offset); } else { acc = item; hasValue = true; } } if (!(hasSeed || hasValue)) { throw new Error('Sequence contains no elements'); } return acc; } //# sourceMappingURL=reduceright.mjs.map