Split a String into an Array Using the split Method

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

#1

Tell us what’s happening:

Your code so far


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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 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


#2

The challenge asks that you split each string into words, but not only by space.
For instance

Hello-World // ["Hello", "World"]

For example you can use a regex that match any non a-z character :slight_smile:
Hope it helps.


#3

if you want by space you must declare ’ ’ space not ‘’ nothing
look at this sites https://regexr.com/ select References and character classes


#5

It is not passing because you forgot to include the period (.)

try this instead.

(/\s|,|.|-/)


#6

thanks your help ,just now I find a method split(/\s|\W/)


#7

Yup. That is way better. Welcome.