Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. /*
  2. In line 4 of Javascript function, a semicolon is missing. Also, we cannot set up a function inside a for loop because
  3. i in the function(x) referred a variable that belongs to the outside scope, the variable i is y.
  4. */
  5.  
  6. /* We can improve the code shown below: */
  7. function f(num){
  8. return function(){
  9. x + num;
  10. };
  11. }
  12. function createArrayOfFunctions(y) {
  13. var arr = [];
  14. for(var i = 0; i<y; i++) {
  15. arr[i] = f(i) ;
  16. }
  17. return arr;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement