1import { findLastIndex, groupBy, intersecting, replaceValue } from '../array';
2
3describe(findLastIndex, () => {
4  it('should return the last index of an item based on a given criteria', () => {
5    const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
6    const predicate = (item: number) => item % 2 === 0;
7    expect(findLastIndex(array, predicate)).toBe(9);
8  });
9});
10
11describe(intersecting, () => {
12  it('should return a list of items that intersect between two given arrays', () => {
13    const a = [1, 2, 3];
14    const b = [1, 2, 3, 4, 5, 6];
15    expect(intersecting(a, b)).toEqual([1, 2, 3]);
16  });
17});
18
19describe(replaceValue, () => {
20  it(`should replace a value in an array`, () => {
21    expect(replaceValue([1, 2, 3], 1, 2)).toEqual([2, 2, 3]);
22    expect(replaceValue([1, 2, 3], 4, 5)).toEqual([1, 2, 3]);
23  });
24});
25
26describe(groupBy, () => {
27  it(`should group list items by returned key`, () => {
28    expect(
29      groupBy([{ name: 'John' }, { name: 'Wick' }], (character) => character.name)
30    ).toMatchObject({
31      John: [{ name: 'John' }],
32      Wick: [{ name: 'Wick' }],
33    });
34  });
35});
36