Last active
April 7, 2018 04:05
-
-
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.
This file contains hidden or 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 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