Also, I just found out about Map, so here's a version that uses that 😁:
functionlucky(s){// split the string into an array so that it can be reducedletsarr=s.split('');// reduce the array into a character -> count mapletcounts=sarr.reduce((acc,c)=>{if(acc.get(c)){acc.set(c,acc.get(c)+1);}else{acc.set(c,1);}returnacc;},newMap());letsmallestCount=Number.MAX_VALUE;// find the smallest frequency in the mapcounts.forEach((count,c)=>{if(count<smallestCount){smallestCount=count;}});letbiggerCount=0;// count how many characters exceed the smallest frequencycounts.forEach((count,c)=>{if(count>smallestCount){biggerCount+=count-smallestCount;}});// exceeding 0 times fullfills point 1leteasyLucky=biggerCount==0;// exceeding only once fullfills point 2lethardLucky=biggerCount==1;// if either is true you have a lucky stringreturneasyLucky||hardLucky;}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Also, I just found out about Map, so here's a version that uses that 😁: