Skip to content

Instantly share code, notes, and snippets.

Created January 13, 2016 01:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
var defaultPrint = (item) => console.log(`Hello, ${item}`)
var myForEach = (list, printFunction = defaultPrint) => {
list.forEach((item) => printFunction(item))
myForEach([{name: "Tomba!"},{name: "Neo Cortex"}], (person) => defaultPrint(
myForEach([{brand: "Ferrari"}, {brand: "Mercedes"}], (car) => defaultPrint(car.brand))
myForEach([{name: "N64", arch: "MIPS"}, {name: "3DS", arch: "ARM9"}], (console) => defaultPrint(`${} - ${item.arch}`))
// in fact we could even use `Array.prototype.forEach` function and avoid the duplication with `myForEach`
// (which does basically what forEach does)
// var forEach = Array.prototype.forEach
//[{name: "Tomba!"},{name: "NeoCortex"}], (person) => defaultPrint(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment