UNPKG

ts-prime

Version:

A utility library for JavaScript and Typescript.

26 lines (25 loc) 880 B
import { reduce } from './reduce'; import { pipe } from './pipe'; var array = [1, 2, 3, 4, 5]; describe('data first', function () { test('reduce', function () { expect(reduce(array, function (acc, x) { return acc + x; }, 100)).toEqual(115); }); test('reduce.indexed', function () { var i = 0; expect(reduce.indexed(array, function (acc, x, index, items) { expect(index).toBe(i); expect(items).toBe(array); i++; return acc + x; }, 100)).toEqual(115); }); }); describe('data last', function () { test('reduce', function () { expect(pipe(array, reduce(function (acc, x) { return acc + x; }, 100))).toEqual(115); }); test('reduce.indexed', function () { expect(pipe(array, reduce.indexed(function (acc, x) { return acc + x; }, 100))).toEqual(115); }); });