Skip to content

Instantly share code, notes, and snippets.

@melvinlee
Last active April 7, 2018 04:05
Show Gist options
  • Save melvinlee/b076b51233c9e953b98b3a779557d847 to your computer and use it in GitHub Desktop.
Save melvinlee/b076b51233c9e953b98b3a779557d847 to your computer and use it in GitHub Desktop.
Given a sentence, find the 1st longest word and the word's length must be in even number.
const findLongestEvenWord = sentence => {
let array = sentence.split(/\s+/);
return array.filter(x => x.length % 2 === 0).sort((a , b) => b.length - a.length )[0];
}
console.log(findLongestEvenWord("The code is self explanatory , I have used the put method"));
console.log(findLongestEvenWord("Once created , you can click on Test and send a JSON as below"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment