Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mohamedhayibor/42ace8b00e1005a88021 to your computer and use it in GitHub Desktop.
Save mohamedhayibor/42ace8b00e1005a88021 to your computer and use it in GitHub Desktop.
function each (array, callback) {
for (var i = 0; i < array.length; i++) {
callback(array[i]);
}
}
each([2, 6, 7], console.log); // => 2, 6, 7
function mapEach (array, callback) {
var result = [];
each(array, function (index) {
return (function (j) {
result.push(callback(j));
}(index));
});
return result;
}
console.log(mapEach([1, 2, 5, 7, 8, 9, 89], function (i) { return i * 2; }));
// => [2, 4, 10, 14, 16, 18, 178]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment