Files
30-seconds-of-code/test/findLastIndex.test.js
2019-08-11 16:20:26 +08:00

12 lines
407 B
JavaScript

const {findLastIndex} = require('./_30s.js');
test('findLastIndex is a Function', () => {
expect(findLastIndex).toBeInstanceOf(Function);
});
test('Finds last index for which the given function returns true', () => {
expect(findLastIndex([1, 2, 3, 4], n => n % 2 === 1)).toBe(2);
});
test('Return default index when not found', () => {
expect(findLastIndex([1, 2, 3, 4], n => n === 5)).toBe(-1);
});