Andrei Calinescu baed72fd3d Explained solution and added alternate (#34718)
* Explained solution and added alternate

Explained why the solution works and added an alternate, less elegant solution for comparison.

* Removed last line per feedback
2019-03-08 14:41:08 -08:00

751 B

title
title
Split a String into an Array Using the split Method

Split a String into an Array Using the split Method

Method

Simply split the string to create a new array of words.

A simple regular expression can be used to achieve this result.

/\W/ Matches any non-word character. This includes spaces and punctuation, but not underscores. It's equivalent to /[^A-Za-z0-9_]/. For more information about Regular Expressions, see the official MDN Documentation.

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");