const arr = [36,19,69,27];
function push_to_array(data, cb){
for(let i=0; i < data.length; i++){
cb(data[i]);
}
}
let test = push_to_array(arr, function(item){
console.log(item);
return item
});
console.log(test)
I apologize in advance for any lack in knowledge, I'm trying to wrap my head around Callbacks and Higher order Functions.
I'm attempting to loop in my callback function and return each value in the array. Right now the console.log(item)
is showing that I'm indeed getting each value, but the return is saying that I am getting undefined. I'm not quite sure why and was just wondering what I'm doing wrong.
Thank you.