async-array-methods
Async methods to manipulate arrays.
Usage
var methods = var AsyncArray = methodsArrayvar filter = methodsfiltervar map = methodsmapvar forEach = methodsforEachvar reduce = methodsreduce
All methods return a promise.
Methods
Callbacks can be made asynchronous by returning a promise, or accepting a function argument, which will be called when the callback finishes.
Otherwise, the callback is treated as synchronous.
filter
Signature: filter(arr, fn, context)
map
Signature: map(arr, fn, context)
fn
is called with each element in parallel.
// [4, 8, 12, 16]
series
This method works like map
,
except that fn
is called with each element in sequence rather than in parallel.
Signature: map(arr, fn, context)
var n = 1// i: 0 delay: 10// i: 1 delay: 50// i: 2 delay: 0// i: 3 delay: 80// [2, 8, 24, 64] { return Math * 10}
forEach
fn
is called with elements in sequence.
Signature: forEach(arr, fn, context)
var count = 0
reduce
Signature: reduce(arr, fn, initial)
// 10
AsyncArray
Signature: AsyncArray(arr)
Methods:
map
series
filter
forEach
reduce
var origin = var odd = originvar even = origin return odd { process} { return { process }} { ov = true return o}