DEV Community

Discussion on: Daily Challenge #298 - Find the Shortest Word

Collapse
 
ruudgianesini profile image
Ruud Gianesini

Here is an answer in node (first time I write something in node :) ) :

function find_short(phrase: string) { 
 return phrase.split(' ').reduce( (p, c, i) => (i==0 || c.length < p.length) ? c : p)
}
Enter fullscreen mode Exit fullscreen mode