Skip to content

Instantly share code, notes, and snippets.

@Fusselwurm
Last active August 29, 2015 13:57
Show Gist options
  • Save Fusselwurm/9368647 to your computer and use it in GitHub Desktop.
Save Fusselwurm/9368647 to your computer and use it in GitHub Desktop.
// Array methods as variations of forEach
({
forEach: function (fn) {
var i;
for (i = 0; i < this.length; i++) {
fn(this[i], i, this);
}
},
map: function (fn) {
var result = [];
this.forEach(function () {
result.push(fn.apply(this, arguments));
});
return result;
},
every: function (fn) {
var result = true;
this.forEach(function () {
result &= fn.apply(this, arguments);
});
return result;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment