Functional Programming - Split a String into an Array Using the split Method

Functional Programming - Split a String into an Array Using the split Method
0.0 0

#1

Tell us what’s happening:
I am using the right code here but it will not pass me

Your code so far



function splitify(str) {
  // Add your code below this line
  return str.split(/\W+/gi)
  
  // Add your code above this line
}
console.log(splitify("This.is.a-sentence"));


**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

#2

What does the failing test say?


#3

The problem was the code wouldn’t stop running so i had to refresh the page and then it solved.


#4

This is my solution:

function splitify(str) {
  // Add your code below this line
  return str.split(/\W/);
  // Add your code above this line
}
splitify("Hello World,I-am code");

#5

Desn’t \W represent any alphanumeric character? I would have thought that this code splits the string on any alphanumeric character as opposed to any NON-alphanumeric character.

I see that your code works, I’m just confused about that part.


#6

\w is different than \W

\w is is used to find a word character (character from a-z, A-Z, 0-9, including the _ (underscore) character).

\W is is used to find a non-word character.