Incorrect Challenge Requirements: "Split a String into an Array...."

The requirements for this challenge incorrectly state what it expects to be returned. I have listed one of the requirements. Take note of the double quotes.

splitify("Hello World,I-am code") should return ["Hello", "World", "I", "am", "code"]

I started this challenge by quickly finding the solution:

return  str.split(/\W/);

only instead of returning it I had it reading out through console.log, which showed me

[ 'Hello', 'World', 'I', 'am', 'code' ]

I did not think to check if that was correct because I could clearly see that the answer called for double quotes and not single quotes. I spent the next who knows how long coming up with this solution

var splitifier = [];
return splitifier = '["' + str.split(/\W/).join('", "').replace(/'([^']+(?='))'/g, '$1').split(',') + '"]';

Only to be frustratingly given an error

splitify("Hello World,I-am code") should return ["Hello", "World", "I", "am", "code"].
// tests completed
// console output
["Hello", "World", "I", "am", "code"]

I spent some time being frustrated and overwhelmed and doubting my abilities before finally checking the solution. To save anyone else some heartache, this should be fixed.

There isn’t a difference between ' and " around a string in JavaScript unless you are trying to avoid escaping characters.

That is to say

let word = "bird";

and

let word = 'bird';

are the same thing.

The only difference comes in when you want to type

let posessive = "the bird's word";

or

let quote = 'He said, "No!"';
1 Like

I believe most javascript engines prefer (in that strings by default are displayed in) double quotes, but it is not a requirement.

As has been said, "snowmonkey"==='snowmonkey' and even

`snowmonkey`==="snowmonkey"

Single quotes, double quotes or (as you’ll find later) template literal backticks… So long as the string inside is the same, the delimiter doesn’t affect its equality.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.