Last active
August 29, 2015 14:15
-
-
Save 0xMatt/74f418b29daf55259ab5 to your computer and use it in GitHub Desktop.
Interview answer
This file contains hidden or 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
<?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) |
This file contains hidden or 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
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