Skip to main content
Module

x/rambda/source/findLastIndex.spec.js

Faster and smaller alternative to Ramda
Latest
File
import { findLastIndex } from './findLastIndex.js'
test('happy', () => { const result = findLastIndex(x => x > 1, [ 1, 1, 1, 2, 3, 4, 1 ])
expect(result).toBe(5)
expect(findLastIndex(x => x === 0, [ 0, 1, 1, 2, 3, 4, 1 ])).toBe(0)})
test('with curry', () => { expect(findLastIndex(x => x > 1)([ 1, 1, 1, 2, 3, 4, 1 ])).toBe(5)})
const obj1 = { x : 100 }const obj2 = { x : 200 }const a = [ 11, 10, 9, 'cow', obj1, 8, 7, 100, 200, 300, obj2, 4, 3, 2, 1, 0 ]const even = function (x){ return x % 2 === 0}const gt100 = function (x){ return x > 100}const isStr = function (x){ return typeof x === 'string'}const xGt100 = function (o){ return o && o.x > 100}
test('ramda 1', () => { expect(findLastIndex(even, a)).toBe(15) expect(findLastIndex(gt100, a)).toBe(9) expect(findLastIndex(isStr, a)).toBe(3) expect(findLastIndex(xGt100, a)).toBe(10)})
test('ramda 2', () => { expect(findLastIndex(even, [ 'zing' ])).toBe(-1)})
test('ramda 3', () => { expect(findLastIndex(even, [ 2, 3, 5 ])).toBe(0)})
test('ramda 4', () => { expect(findLastIndex(even, [])).toBe(-1)})