Skip to content

Instantly share code, notes, and snippets.

@tybenz
Created January 14, 2015 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tybenz/69bb9deea633b0e851c8 to your computer and use it in GitHub Desktop.
Save tybenz/69bb9deea633b0e851c8 to your computer and use it in GitHub Desktop.
Better call-n-times
function range(val) {
var arr = [];
for (var i = 0; i < val; i++) {
arr.push(i);
}
return arr;
}
function logAndReturn() {
console.log('foo');
return 'foo';
}
var returns = range(3).map(logAndReturn);
assert.equal(returns.length, 3);
assert.equal(returns[0], 'foo');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment