array-comprehensions
Array comprehensions if you don't want to use 6to5 or traceur.
Installation
npm install array-comprehensions
Usage
var forOf = ; { return x+1;} { return x*y;} { return x*x;} { return x>1} // [for (x of [1,2,3]) inc(x)]; // => [2, 3, 4] // [for (x of [1,2,3]) for (y of [3,2,1]) mul(x,y)]; // => [3, 2, 1, 6, 4, 2, 9, 6, 3] // [for (x of [1,2,3]) if (isGreatherThan1(x)) sqr(x)]; // => [4, 9]
API
forOf
forOf(iterable, do)
Execute the function do
for each item of iterable
.
; // => [2, 3, 4]
forOf(iterable, condition, do)
Execute the function do
for each item of iterable
that fullfills the condition
.
; // => [4,16]
forOf(iterable1, iterable2, do)
Execute the function do
for each item of iterable1
with every item of iterable2
.
; // => [1,2,2,4]