I pass all the tests with a few lines of code.
When I look at the provided solution I want to run away!
Can anyone tell me why my solution is missing compare to the given solution?
function calculateTotalSalaries(data) {
// Write your code here
let res = 0
for (const key in data) {
if (Array.isArray(data[key])) {
res += data[key].map(x => x.salary).reduce((acc, item) => acc + item, 0)
} else {
res += calculateTotalSalaries(data[key])
}
}
return res
}