Skip to content

Instantly share code, notes, and snippets.

@markjanzer
Created June 29, 2015 22:10
Show Gist options
  • Save markjanzer/7136155c57ca3c26cb55 to your computer and use it in GitHub Desktop.
Save markjanzer/7136155c57ca3c26cb55 to your computer and use it in GitHub Desktop.
// 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