deno.land / x / rambda@v9.1.1 / source / findLast.spec.js

findLast.spec.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { findLast } from './findLast.js'
test('happy', () => { const result = findLast(x => x > 1, [ 1, 1, 1, 2, 3, 4, 1 ]) expect(result).toBe(4)
expect(findLast(x => x === 0, [ 0, 1, 1, 2, 3, 4, 1 ])).toBe(0)})
test('with curry', () => { expect(findLast(x => x > 1)([ 1, 1, 1, 2, 3, 4, 1 ])).toBe(4)})
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(findLast(even, a)).toBe(0) expect(findLast(gt100, a)).toBe(300) expect(findLast(isStr, a)).toBe('cow') expect(findLast(xGt100, a)).toEqual(obj2)})
test('ramda 2', () => { expect(findLast(even, [ 'zing' ])).toBeUndefined()})
test('ramda 3', () => { expect(findLast(even, [ 2, 3, 5 ])).toBe(2)})
test('ramda 4', () => { expect(findLast(even, [])).toBeUndefined()})
rambda

Version Info

Tagged at
2 months ago