Longest Word

Published by Steven Bonfadini in

Write a function that finds the longest word in a sentence and returns it. If two or more words are the biggest, return the word closest to the start of the sentence. Characters such as apostrophe, commas, periods, etc count as letters (e.g. O'Connor is 8 characters long).

Examples

longestWord("Hello darkness my old friend") ➞ "darkness"

longestWord("Hello there mate") ➞ "Hello"

longestWord("Kayla's toy is plastic") ➞ "Kayla's"

Notes

N/A

Watch a quick demo on how Edabit works.