Skip to content

Instantly share code, notes, and snippets.

@martin-mok
Last active May 23, 2019 17:36
Show Gist options
  • Save martin-mok/3db267016be01b9daf8900b523d5997d to your computer and use it in GitHub Desktop.
Save martin-mok/3db267016be01b9daf8900b523d5997d to your computer and use it in GitHub Desktop.
/*
It's a scoping bug, it can be corrected by using let
*/
function createArrayOfFunctions(y) {
/*
A function that create an array of function, each have one input, and return the input value by adding the index
*/
let arr = [];
for (let i = 0; i < y; i++) {
arr[i] = function(x) {
return x + i;
};
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment