Having some difficulty skipping callbacks returns. Here is the query:
Create a function named
tap
that takes an array calleditems
and a callback function, cb. The callback function should be executed on the array, and then the array itself should be returned no matter what the callback returns.
Here's My Solution:
function tap(items, cb){
let result = items.map(cb)
return result;
}
Examples:
console.log(tap([1, 2, 3], function (items) {
items.pop();
})).reverse(); // [2,1]
console.log(tap(["a", "b", "c"], function (items) {
return items[0];
})); // ["a","b","c"]
By implementing this code, I expect it to apply the callback functions to the items array.
I encountered the following results for each test case:
a. TypeError: items.pop is not a function
b. [ 'a', 'b', 'c' ]