Generation

generate functionMon, 12 Jun 2023

You will be given an array of 5 named objects, "wet clothes", "jelly beans", "cement mix", "rocks", and "dirty laundry". Your boss has an array of tumblers, a dryer(), a flavorer(), a mixer(), a tumbler(), and a washer(). Your job is to take each object and using JavaScript, programatically tell the automated robotics system which tumbler to put each object in by passing the correct object as an argument to that tumbler's function given to you, the function will modify the object and then return the modified object. Your job is to return an array with the modified objects. Afterwards, as part of the challenge, you can explain your thought and coding process to the boss. function tumbler(items, functions) {

return items.map(function(item, index) { return functions[index](item); }); } function dryer(wetClothes) { return wetClothes + ' are dry'; } function flavorer(jellyBeans) { return jellyBeans + ' are sweet'; } function mixer(cementMix) { return cementMix + ' is mixed'; } function tumbler(rocks) { return rocks + ' are tumbled'; } function washer(dirtyLaundry) { return dirtyLaundry + ' are clean'; } var items = ['wet clothes', 'jelly beans', 'cement mix', 'rocks', 'dirty laundry']; var functions = [dryer, flavorer, mixer, tumbler, washer]; tumbler(items, functions); // Output: [ 'wet clothes are dry', // 'jelly beans are sweet', // 'cement mix is mixed', // 'rocks are tumbled', //

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant