Skip to content

Commit

Permalink
initial code and an example
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jun 8, 2012
0 parents commit 5c26bd4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions example/map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var concatMap = require('../');
var xs = [ 1, 2, 3, 4, 5, 6 ];
var ys = concatMap(xs, function (x) {
return x % 2 ? [ x - 0.1, x, x + 0.1 ] : [];
});
console.dir(ys);
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function (xs, fn) {
var res = [];
for (var i = 0; i < xs.length; i++) {
var x = fn(xs[i]);
if (Array.isArray(x)) res.push.apply(res, x);
else res.push(x);
}
return res;
};

0 comments on commit 5c26bd4

Please sign in to comment.