Need Help Understanding .reduce (More Intricately)

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);
    
}

Sorry about that. I thought it would show. I’ve edited it into the post :slight_smile:

After a nights rest this makes a lot of sense. I was definitely over analyzing a bit. Thanks for the quick response and thorough answer Randell.