JSFiddle - React, Tailwind, and code Playground
by Jake Overall
JavaScript
/* we have an i5 processor and are currious as to what cores are needed when we are playing Minecraft and what the total processor drain minecraft causes.
write a function that can take in our array of processors and determine if the processor is in use.
Then use a callback to log the total ammount output by all cores that are in use */
var processorDrain = 0;
var processors = [{
core: 1,
inUse: true,
output: 4000
}, {
core: 2,
inUse: false,
output: 100
}, {
core: 3,
inUse: true,
output: 1170
}, {
core: 4,
inUse: true,
output: 3250
}, {
core: 5,
inUse: false,
output: 670
}];
var minecraftDrain = function (arr, cb) {
for (var i = 0; i < arr.length; i++) {
if (arr[i].inUse) {
cb(arr[i]);
}
}
};
var processorStatus = function (processor) {
processorDrain += processor.output;
return console.log("core " + processor.core + " is using " + processor.output + " for a total of " + processorDrain);
};
minecraftDrain(processors, processorStatus);