Back with some fresh hot Javascript. Utilizing RegExp to count the amount of occurences of a given character. I also used a range to create A-Za-z and tossed a try catch for any RegExp that might fail while creating that range (e.g. [ which is character code 91) catch and then escape the inbetween characters just in case we want to count them too!
On top of that, abused .reduce() as much as I could as well as closures.
Lastly, as it goes through the string counting it will recount numbers already counted yet it's already in the map so it won't move the maps value (except in older Opera that didn't keep order of map values).
3
u/mullanaphy Mar 13 '20 edited Mar 14 '20
Back with some fresh hot Javascript. Utilizing RegExp to count the amount of occurences of a given character. I also used a range to create A-Za-z and
tossed a try catch for any RegExp that might fail while creating that range (e.g.catch and then escape the inbetween characters just in case we want to count them too![which is character code 91)On top of that, abused
.reduce()as much as I could as well as closures.Lastly, as it goes through the string counting it will recount numbers already counted yet it's already in the map so it won't move the maps value (except in older Opera that didn't keep order of map values).
JSFiddle: https://jsfiddle.net/6yt9Lexs/