module
collections
Source: collections/
Methods
inner
filter(fn, collection) → (Array or Object)
Filters an array/object based on the boolean evaluation of the passed function.
Example
//Arrays
filter(x => x > 1, [1,2,3]) // -> [2,3]
//Objects
filter(x => x > 1, {a:1,b:2}) // -> {b:2}
Parameters
Name | Type | Optional | Description |
---|---|---|---|
fn |
function() |
|
Reduce function |
collection |
(Array or Object) |
|
iterable collection to traverse |
- See also
- Returns
-
(Array or Object)
inner
map(fn, collection) → (Array or Object)
Maps over an array/object applying the passed function
Example
//Arrays
map(x => x+1, [1,2,3]) // -> [2,3,4]
//Objects
map(x => x+1, {a:1,b:2}) // -> {a:2,b:3}
Parameters
Name | Type | Optional | Description |
---|---|---|---|
fn |
function() |
|
Reduce function |
collection |
(Array or Object) |
|
iterable collection to traverse |
- See also
- Returns
-
(Array or Object)
inner
reduce(fn, init, collection) → any type
Reduces an array/object based on the reduction function and the initialization value passed
Example
//Arrays
reduce((a,b)=> a+b,0,[1,2,3]) // -> 6
reduce((a,b)=> a.concat(b+1),[],[1,2,3]) // -> [2,3,4]
//Objects
reduce((a,v,k)=> ({..a,[k],v+1}),{},{a:1,b:2}) // -> {a:2,b:3}
Parameters
Name | Type | Optional | Description |
---|---|---|---|
fn |
function() |
|
Reduce function |
init |
any type |
|
Initial value to accumulate |
collection |
(Array or Object) |
|
iterable collection to traverse |
- See also
- Returns
-
any type