Skip to content

Instantly share code, notes, and snippets.

@0xMatt
Last active August 29, 2015 14:15
Show Gist options
  • Save 0xMatt/74f418b29daf55259ab5 to your computer and use it in GitHub Desktop.
Save 0xMatt/74f418b29daf55259ab5 to your computer and use it in GitHub Desktop.
Interview answer
<?php
function most_letters_in_a_word($string) {
$string = preg_replace("/[^A-Za-z]/", ' ', $string);
foreach(array_filter(explode(' ', $string)) as $word) {
$words[max(count_chars($word, 1))] = $word;
}
return $words[max(array_keys($words))];
}
var_dump(most_letters_in_a_word("O Romeo, Romeo! Wherefore art thou Romeo?")); // string 'Wherefore' (length=9)
Write a function that takes in a string and returns the
word that has the most repeated single letter out of all
the words in the string.
Given the string "O Romeo, Romeo! Wherefore art thou Romeo?"
Your function should return "wherefore" since the letter 'e'
is repeated most often.
** strip non alphabetic characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment