Created
October 21, 2015 12:25
-
-
Save bydga/80f72aaa34ccf4906f2c to your computer and use it in GitHub Desktop.
functions solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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