Created
February 25, 2020 11:18
-
-
Save EngPeterShaker/676b976f32c488edeb5163e349f4c7b0 to your computer and use it in GitHub Desktop.
find longest word
This file contains 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 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