deno.land / x / rambda@v9.1.1 / source / partition.spec.js
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566import { partition } from './partition.js'
test('with array', () => { const predicate = x => x > 2 const list = [ 1, 2, 3, 4 ]
const result = partition(predicate, list) const expectedResult = [ [ 3, 4 ], [ 1, 2 ], ]
expect(result).toEqual(expectedResult)})
test('with object', () => { const predicate = (value, prop) => { expect(typeof prop).toBe('string')
return value > 2 } const hash = { a : 1, b : 2, c : 3, d : 4, }
const result = partition(predicate)(hash) const expectedResult = [ { c : 3, d : 4, }, { a : 1, b : 2, }, ]
expect(result).toEqual(expectedResult)})
test('readme example', () => { const list = [ 1, 2, 3 ] const obj = { a : 1, b : 2, c : 3, } const predicate = x => x > 2
const result = [ partition(predicate, list), partition(predicate, obj) ] const expected = [ [ [ 3 ], [ 1, 2 ] ], [ { c : 3 }, { a : 1, b : 2, }, ], ] expect(result).toEqual(expected)})
Version Info