Created
September 17, 2025 00:18
-
-
Save AbeEstrada/ef00e0a9c6ca1871267640c2315035a1 to your computer and use it in GitHub Desktop.
Exercise: find the longest word in a sentence
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
const longestWord = (str: string): void => { | |
if (str?.length === 0) return; | |
const words: string[] = str.split(" "); | |
const longest: string = words.reduce( | |
(a, b) => (b.length > a.length ? b : a), | |
"", | |
); | |
console.log(longest.length, longest); | |
}; | |
longestWord("The quick brown fox jumped over the lazy dog"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment