ts-prime
Version:
A utility library for JavaScript and Typescript.
27 lines (26 loc) • 867 B
JavaScript
import { indexBy } from './indexBy';
import { pipe } from './pipe';
var array = [
{ dir: 'left', code: 97 },
{ dir: 'right', code: 100 },
];
var expected = {
left: { dir: 'left', code: 97 },
right: { dir: 'right', code: 100 },
};
describe('data first', function () {
test('indexBy', function () {
expect(indexBy(array, function (x) { return x.dir; })).toEqual(expected);
});
test('indexBy.indexed', function () {
expect(indexBy.indexed(array, function (x) { return x.dir; })).toEqual(expected);
});
});
describe('data last', function () {
test('indexBy', function () {
expect(pipe(array, indexBy(function (x) { return x.dir; }))).toEqual(expected);
});
test('indexBy.indexed', function () {
expect(pipe(array, indexBy.indexed(function (x) { return x.dir; }))).toEqual(expected);
});
});