Which fix removes the bug?
const words = 'red green blue'.split(); console.log(words.length); // expected 3
- Use
split(',')on it - Pass a space:
split(' ') - Call
trim()after split - Read
words.sizeinstead
With no separator, split returns the whole string as a single element.
Play Problem Solving ▸