var kiko = [1,2,3,4,5,6];
var forEach = function(array, newArray, action){
for (var i=0; i<array.length; i++){
var newArray = [];
newArray.action(array[i]);
};
};
forEach(kiko, newKiko, push)
newKiko
I'm studying abstract functions, and I came across an example of the Eloquent Javascript book in which an array.map version is created from scratch. I tried doing mine, which scans an array, and creates another array for each item it passes through. I'm getting the error "Push is not defined" but it's a native method of arrays in JS. What could be going wrong?
I tried a second variant, but it gives me an empty array:
var kiko = [1,2,3,4,5,6];
var forEach = function(array, action){
for (var i=0; i<array.length; i++){
action(array[i]);
};
};
forEach(kiko, function(element){
var newKiko = [];
newKiko.push(element);
})
newKiko