I'm trying to use Closure in JS in order to declare a function named **expandArray()**
which contain an Array named **myArray**
and Returns an anonymous function that directly modifies myArray by increase the values by 1 than the returned function then returns the value of **myArray**
. My Problem here one the last part where the returned function return a function not Array value ?!
This is my code
function expandArray() {
const myArray = [1, 1, 1];
return function () {
myArray.forEach( function (num, index, myArray) {
myArray[index] = num + 1;
});
return myArray;
};
}
console.log(expandArray());