I think the challenges asks for filling an empty object with keys that are the numbers (as strings of course in case of object keys) and their values should be the amount of occurrences of that number in an array.
I can’t seem to solve the problem with the usage of a single forEach call.
Whenever I do this, the object keys seem to be correct but the values are undefined or NaNs.
This step is pretty unreasonable and I opened an issue for it some days ago. I haven’t heard anything back yet.
Even with the suggested change in the text, I’m not sure it will be good enough for people to solve this, at least not using the fixed solution it requires (it is using a regex that locks you into one solution).
Use el to create a computed property name on the counts object. Assign it a default value of 0 , if the property already exists increment it.
I would suggest you skip forward and look at the solution. In this case, it isn’t going to change anything as most people are fairly unlikely (in my opinion) to solve this as required.
I do not get what you mean by regex. Where do we use regex in our getMode()?
I got solution from your open issue. However my solution before this was so close setting fallback straight to 1.
array.forEach((el) => counts[el] = counts[el] + 1 || 1);
It appears to work fine in test under VS Code. It seems very unnecessary that we have to initialize it to 0 then increment. I fail to see what is wrong with my solution that is even less characters and appears to work just fine, but maybe someone knowledgeable like you can let me know.
The test is using a regex, you are not asked to use a regex.
It should not matter how you write it as long as the final object is correct. Which requires us to work on actual data and check the object for correctness.
As said, there is an issue open for this and hopefully, it will be fixed at some point.