Skip to content

Instantly share code, notes, and snippets.

@bydga
Created October 21, 2015 12:25
Show Gist options
  • Select an option

  • Save bydga/80f72aaa34ccf4906f2c to your computer and use it in GitHub Desktop.

Select an option

Save bydga/80f72aaa34ccf4906f2c to your computer and use it in GitHub Desktop.
functions solution
var fruits = ["apple", "pear", "banana", "mango"]
var functions = []
//EDIT THIS:
for (var i=0; i<fruits.length; i++) {
var fruit = fruits[i]
functions.push(
function(fr) {
return function() {
console.log(fr)
}
}(fruit)
)
}
//DO NOT EDIT BEYOND THIS LINE
for (var j=0; j<functions.length; j++) {
functions[j]()
}
var fruits = ["apple", "pear", "banana", "mango"]
var functions = []
//EDIT THIS:
for (var i=0; i<fruits.length; i++) {
var fruit = fruits[i]
functions.push(
function(fr) {
console.log(fr)
}.bind(null, fruit)
)
}
//DO NOT EDIT BEYOND THIS LINE
for (var j=0; j<functions.length; j++) {
functions[j]()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment