Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- In line 4 of Javascript function, a semicolon is missing. Also, we cannot set up a function inside a for loop because
- i in the function(x) referred a variable that belongs to the outside scope, the variable i is y.
- */
- /* We can improve the code shown below: */
- function f(num){
- return function(){
- x + num;
- };
- }
- function createArrayOfFunctions(y) {
- var arr = [];
- for(var i = 0; i<y; i++) {
- arr[i] = f(i) ;
- }
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement