Skip to content

Instantly share code, notes, and snippets.

@EngPeterShaker
Created February 25, 2020 11:18
Show Gist options
  • Save EngPeterShaker/676b976f32c488edeb5163e349f4c7b0 to your computer and use it in GitHub Desktop.
Save EngPeterShaker/676b976f32c488edeb5163e349f4c7b0 to your computer and use it in GitHub Desktop.
find longest word
const str = sen.replace(/[^a-zA-Z ]/g, ""); // replace strange characters
const words = str.split(' '); // convert to array of strings
const sorted = words.sort((a, b) => b.length - a.length); // sort descending according string length
return sorted[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment