Can anyone explain in detail how this piece of code works?
const yourAmazingFunction = (salaries) => Object.values(salaries).reduce((acc, el) => acc + el, 0);
specifically this:
((acc, el) => acc + el, 0);
Here's all the code:
const nonEmptySalaries = {
John: 100,
Ann: 160,
Pete: 130
};
const emptySalaries = {};
const yourAmazingFunction = (salaries) => Object.values(salaries).reduce((acc, el) => acc + el, 0);
const firstResult = yourAmazingFunction(nonEmptySalaries)
const secondResult = yourAmazingFunction(emptySalaries)
console.log(firstResult); // 390
console.log(secondResult); // 0 ```