Skip to content

Instantly share code, notes, and snippets.

@peterchaula
Last active October 24, 2016 14:36
Show Gist options
  • Save peterchaula/de39d604caf70ff4dcd306452beac776 to your computer and use it in GitHub Desktop.
Save peterchaula/de39d604caf70ff4dcd306452beac776 to your computer and use it in GitHub Desktop.
/**
Fix this code
var multiplyByIndex = [];
for (var i = 0; i < 100; i ++) {
multiplyByIndex[i] = function(inputNum) {
return inputNum * i;
};
}
multiplyByIndex[5](2)
output: 200
*/
var multiplyByIndex = [];
for (var i = 0; i < 100; i ++) {
multiplyByIndex[i] = (function(i) {
return function(inputNum){
return inputNum * i;
};
})(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment