-1

This is silly, but I'm having hard time understanding how these two statements outputs different results.

'theyyyyy wheels on q bus'.split(' ').reduce((shortest, w) => {
   return  w.length < shortest.length ? shortest = w : shortest;
 }) // 'q'

'theyyyyy wheels on q bus'.split(' ').reduce((shortest, w) => {
  return shortest.length > w.lenght ? shortest = w : shortest;
}) // 'theyyyyy'

1 Answers1

1

In the second case, you have w.lenght which is undefined. Change to w.length.

B. Fleming
  • 7,170
  • 1
  • 18
  • 36