Created
June 29, 2015 22:10
-
-
Save markjanzer/7136155c57ca3c26cb55 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
// function that creates an object that tells me how many times each letter | |
// was repepated in a string. | |
// Also have it tell me which letter was repeated the most and how many times it repeated | |
function objectify(str) { | |
str = str.toLowerCase(); | |
var obj = {}; | |
for (i = 0; i < str.length; i++) { | |
if (str[i] in obj) | |
obj[str[i]] += 1; | |
else | |
(obj[str[i]] = 1); | |
} | |
return obj; | |
var longest = 1; | |
for (i = 0; i < obj.length; i++) | |
if (obj[i] > 1) | |
obj[i] = longest; | |
return longest; | |
} | |
console.log(objectify("blOoopadoodledoo")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment