daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 52 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. const maxStringCounter = str => {
  2.   let obj = {};
  3.  
  4.   str.split("").forEach(el => {
  5.     if (obj[el]) {
  6.       return (obj[el] += 1);
  7.     } else {
  8.       return (obj[el] = 1);
  9.     }
  10.   });
  11.  
  12.   const values = Object.values(obj);
  13.   const keys = Object.keys(obj); //?
  14.   const maxValue = Math.max(...values);
  15.   const indexOfLargestValue = values.indexOf(maxValue);
  16.  
  17.   return keys[indexOfLargestValue];
  18. };
  19.  
  20. maxStringCounter("44123"); // 4
  21. maxStringCounter("441111123"); // 1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top