Hey all, I’m practicing functional programming to pass job technical Interviews. This type of coding is relatively new to me and I need some help understanding some things.
This question is a warmup challenge on HackerRank here ->
So… I understand .reduce() pretty well and I’ve found a solid answer to this HackerRank question but I need help interpreting whats actually going on. I don’t want to move on with my practice without understanding this :). Thanks!
My answer to the HackerRank challenge ->
function equalizeArray(arr) {
let countArr = Object.values(
arr.reduce((accumulator, currentValue) => {
accumulator[currentValue] = !accumulator[currentValue] ? 1 : accumulator[currentValue] + 1;
return accumulator;
}, {})
);
return arr.length - Math.max(...countArr);
}