Skip to content

Instantly share code, notes, and snippets.

@psqq
Created November 16, 2015 21:11
Show Gist options
  • Save psqq/dd2adbca121326c75d16 to your computer and use it in GitHub Desktop.
Save psqq/dd2adbca121326c75d16 to your computer and use it in GitHub Desktop.
"use strict";
let _ = require("underscore");
let g = {};
function createArray (name, n, callback) {
let res = [];
for (let i=0; i<n; i++) {
res[i] = callback(i, res);
}
g[name] = res;
}
createArray("a", 10, i => i);
createArray("b", 10, (i, arr) => {
let sum = i;
_.each(arr, e => sum += e);
return sum;
});
g.c = _.map(g.b, e => e+1);
g.x1 = _.reduce(g.b, (m, e) => m + e, 0);
g.x2 = _.reduce(g.c, (m, e) => m + e, 0);
g.x3 = _.reduce(g.a, (m, e) =>
console.dir(g);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment