list.reject
This commit is contained in:
parent
3aa40ae2c2
commit
f57452ece2
|
|
@ -14,6 +14,13 @@ export const list = {
|
|||
}
|
||||
return acc
|
||||
},
|
||||
reject: async (list: any[], cb: Function) => {
|
||||
let acc: any[] = []
|
||||
for (const value of list) {
|
||||
if (!(await cb(value))) acc.push(value)
|
||||
}
|
||||
return acc
|
||||
},
|
||||
reduce: async (list: any[], cb: Function, initial: any) => {
|
||||
let acc = initial
|
||||
for (const value of list) acc = await cb(acc, value)
|
||||
|
|
|
|||
|
|
@ -193,6 +193,15 @@ describe('collections', () => {
|
|||
`).toEvaluateTo([3, 4, 5])
|
||||
})
|
||||
|
||||
test('list.reject doesnt keep matching elements', async () => {
|
||||
await expect(`
|
||||
is-even = do x:
|
||||
(x % 2) == 0
|
||||
end
|
||||
list.reject [1 2 3 4 5] is-even
|
||||
`).toEvaluateTo([1, 3, 5])
|
||||
})
|
||||
|
||||
test('list.reduce accumulates values', async () => {
|
||||
await expect(`
|
||||
add = do acc x:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user