Task Instructions: Your task is to create a function called multiMap that takes in two arrays as parameters: one array of values and one array of callbacks. The multiMap function should return an object where the keys correspond to the elements in the values array. Each key's value should be an array containing the outputs from each callback function, with the input being the key itself.
My Approach:
let obj = {};
for(let i = 0; i < arrVals.length; i++) {
obj[arrVals[i]] = [arrCallbacks.apply(null, arrVals[i])];
}
return obj;
}
console.log(multiMap(['catfood', 'glue', 'beer'], [function(str) { return str.toUpperCase(); }, function(str) { return str[0].toUpperCase() + str.slice(1).toLowerCase(); }, function(str) { return str + str; }]));
// expected output: { catfood: ['CATFOOD', 'Catfood', 'catfoodcatfood'], glue: ['GLUE', 'Glue', 'glueglue'], beer: ['BEER', 'Beer', 'beerbeer'] }
Reflections:
While my object keys are correctly set, I encountered difficulty passing the values from the arrVals parameter into the anonymous functions listed in the arrCallbacks parameter. Even after attempting to set my key value to [arrCallbacks[i](arrVals[i])]
, only the first element was populated in the array. I need all three values from the functions to be passed into the value of each key. I'll have to troubleshoot this further...