Skip to content

Instantly share code, notes, and snippets.

@jalehman
Created October 15, 2015 03:02
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 jalehman/03fa90687aba636d05eb to your computer and use it in GitHub Desktop.
Save jalehman/03fa90687aba636d05eb to your computer and use it in GitHub Desktop.
var each = function(list, f) {
for (var i = 0; i < list.length; i++) {
f(list[i]);
}
};
var map = function(list, f) {
var arr = [];
for (var i = 0; i < list.length; i++) {
arr.push(f(list[i]));
}
return arr;
};
var numbers = [0,1,2,3,4,5];
each(numbers, function(x) { console.log(x+1); });
map(numbers, function(x) { return x + 1; });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment