Let’s assume I need a function to get the frequency of the vals of an array, the output should be an object of key value pairs representing how many times a val is repeated in the given arr, the order doesn’t matter. Example:
Thank you sir, I think I get it now. So basically in the first iteration (considering this as the input [1, 3, 4, 1]) because 1 doesn’t exist as a prop in the freqCounter object, 0 will be used as the value of 1, plus 1, then in the final iteration it’s going to be truthy because 1 already exists and we just add 1 to its current val.
It’s good that I finally understand the operation, however I do feel using a basic ternary operator is just easier to read, well at least for less inexperienced programmers such as myself.