Created
January 17, 2017 05:27
-
-
Save hakimelek/b86d90df0b8399405a1cc6d109f34a58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var customary = function (str) { | |
var freq = {}; | |
var stringArray = str.split(''); | |
for (let i=0; i<stringArray.length; i++) { | |
let char = stringArray[i]; | |
if (freq.hasOwnProperty(char)) freq[char]++; | |
else { | |
freq[char] = 0; | |
} | |
} | |
var freqSorted = Object.keys(freq).sort(function (a,b) { | |
return freq[b] - freq[a]; | |
}); | |
var result = ''; | |
freqSorted.forEach(function(item) { | |
result+=item; | |
}); | |
var _index = result.indexOf('_'); | |
return result.substring(0, _index); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment