Same thing, but using a reducer instead of sorting.
constgetLongestWordOf=(sentence='')=>{returnsentence.split(' ').reduce((longest,current)=>{returncurrent.length>longest.length?current:longest;})}getLongestWordOf('I am just another solution to the same problem');
Same thing, but using a reducer instead of sorting.
EDIT: This approach seems to be faster than the sorting one! jsperf.com/longestwordjs/1
This is what I thought to do as well 😄
Good one, didn't think of reduce 👏