Split a String into an Array Using the split Method \s

Hi there, I would like to know why simply \s as for RegEx for whitespace did not work.
Your code so far


function splitify(str) {
  // Add your code below this line
    let x= str.split(/\s/);
    return x;

  // Add your code above this line
}
splitify("Hello World,I-am code");
    console.log(splitify);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method

It’s doing what it should do. Splitting by whitespace.

What behavior are you expecting? If you think it should split by words, this regex won’t work because this string includes a comma and dash.

Interesting. I might have a terminology problem. I thought ‘whitespace’ meant space, dash, underline, etc.?

Nope.

White space means any number of blank spaces.

1 Like