Skip to main content
Module

x/rambda/partition.spec.js

Faster and smaller alternative to Ramda
Go to Latest
File
import { partition } from './partition'
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)})