Javascript reduce() to find the shortest word in a string
问题 I have a function that finds the longest word in a string. function findLongestWord(str) { var longest = str.split(' ').reduce((longestWord, currentWord) =>{ return currentWord.length > longestWord.length ? currentWord : longestWord; }, ""); return longest; } console.log(findLongestWord("The quick brown fox jumped over the lazy dog")); I'm having a hard time converting this to find the shortest word. Why can't I just change currentWord.length > longestWord.length to currentWord.length <