@cmarmar/

Create Functions

ES6

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Create a function, which returns an array of functions. Each function returns their index in the array.  Here is an example:

// ```
// var arrayOfFunctions = createFunctions(5); // create an array, containing 5 functions

// arrayOfFunctions[0](); // must return 0
// arrayOfFunctions[3](); // must return 3
// arrayOfFunctions[arrayOfFunctions.length - 1 ](); // must return 4
// ```

// Apply concepts such as Closure and Scope to this problem.  Please add comments if you struggle with the problem, this will help us assign partial credit!

// NOTE: YOU MAY NOT USE THE ES6 KEYWORD 'LET' IN THIS PROBLEM. FOR FULL CREDIT, YOU MUST COMPLETE THIS PROBLEM USING ONLY ES5


function createFunctions(num){
  var funcBank= {
    0: function(){
    return 0},
    1: function(){
    return 1},
    2: function(){
    return 2},
    3: function(){
    return 3},
    4: function(){
    return 4},
    5: function(){
    return 5},
    6: function(){
    return 6},
    7: function(){
    return 7},
    8: function(){
    return 8},
    9: function(){
    return 9},
    10: function(){
    return 10},
    11: function(){
    return 11},
    12: function(){
    return 12},
    13: function(){
    return 13},
    14: function(){
    return 14},
    15: function(){
    return 15},
    16: function(){
    return 16},
    17: function(){
    return 17},
    18: function(){
    return 18},
    19: function(){
    return 19},
    20: function(){
    return 20},
    21: function(){
    return 21},
    22: function(){
    return 22}
  }
  var arrayOfFunctions= [];
  for(var i = 0; i<num; i++) {
    arrayOfFunctions.push(funcBank[i])
  }
  return arrayOfFunctions
}
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie