← Back to challenges

Recursion: Find The Longest Word

JavaScriptHardrecursionsortingstringsarrays

Instructions

Write a recursive function that will return the longest word in a sentence. In cases where more than one word is found, return the first one.

Examples

findLongest("I will and ever will be gratefully and perpetually loving you Tesh!😘") ➞ "perpetually"

findLongest("A thing of beauty is a joy forever.") ➞ "forever"

findLongest("Forgetfulness is by all means powerless!") ➞ "forgetfulness"

findLongest("The word strengths is the longest and most commonly used word with a single vowel.") ➞ "strengths"

Notes

  • Special characters and symbols don't count as part of the word.
  • Return the longest word found in lowercase letters.
  • You are expected to solve this challenge via a recursive approach.
  • An iterative version of this challenge can be found via this link.
  • A collection of challenges in recursion can be found via this link.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.