Lodash words() issue

Hi all.

I’m working through the Lodash project and am a little confused with the words() method.

My original solutions was this:

words(string) {
        let array = [];
        array.push(string.split(' '));
        return array;

but I was continually not passing the tests.

The solution is slightly shorter:

words(string) {
    let array = string.split(' ');
    return array;

I’m unsure how this is different from the solutions, albeit a little more lines of code.


The .split() method already returns an array, so you are pushing an array to an array. (reference)

Here’s an example of the differences in what will be returned if you passed the string This is a test to each of the solutions you posted:

// Your original solution
[ [ 'This', 'is', 'a', 'test' ] ]

// The Codecademy solution
[ 'This', 'is', 'a', 'test' ]

Ahhhhh, okay that makes sense. It was hard to see that in the results that were being returned to me in my IDE.

Thank you very much.