You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the mode() on for example the following array: [ 'i', '_', ')', '_', 'B', '_' ] the result is [ '_', ')', '_', 'B', '_' ], but the expected result should be: [ '_' ]
The text was updated successfully, but these errors were encountered:
Possible solution (still to be implemented and tested and adapted for multi-dimensional arrays)
// find the mode (or modes) in a one-dimensional arrayfunctionmode(list){// get all the unique occurances and the amount of times they occurletoccurances={};list.forEach((o)=>{if(!occurances[o]){occurances[o]=0;}occurances[o]++;});// for all the items save the best streak (or streaks)letmodes=[];letstreak=0;Object.keys(occurances).forEach((o)=>{if(occurances[o]>streak){streak=occurances[o];modes=[o];}elseif(occurances[o]===streak){modes.push(o);}});returnmodes;}
When using the
mode()
on for example the following array:[ 'i', '_', ')', '_', 'B', '_' ]
the result is[ '_', ')', '_', 'B', '_' ]
, but the expected result should be:[ '_' ]
The text was updated successfully, but these errors were encountered: