Last active
September 18, 2020 13:07
-
-
Save marklin-latte/86940c19dee18a924e654264004fe89b to your computer and use it in GitHub Desktop.
This file contains 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
// Bug Version | |
function createArrayOfFunctions(y) { | |
var arr = []; | |
for(var i = 0; i<y; i++) { | |
arr[i] = function(x) { return x + i; } // <=== the i is bug ! the i will always be y+1; | |
} | |
return arr; | |
} | |
// Current Version | |
function createArrayOfFunctions(y) { | |
var arr = []; | |
for(var i = 0; i<y; i++) { | |
arr[i] = ((i) => { | |
return function(x){return x + i;} | |
})(i); | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment