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

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Great lesson as always Mr. Ian thanks a lot
function splitify(str) {
return str.split(/\W/);
}
console.log(splitify("Hello World, I-am code"));

zken
Автор

Hi Man,
can you have a look to the following version via replace method.
function splitify(str) {
// Only change code below this line
let slicedStr = str.slice();
let replacedStr = slicedStr.replace(/, |-/g, " ");
let splittedStr = replacedStr.split(" ");
return splittedStr;
// Only change code above this line
}
console.log(splitify("Hello World, I-am code"));
But, it didn't work out with daught)) in replace method...
Your solution is pretty easy and, I assume required more practice to be aware of regular expressions and use of short solutions in general.
Thanks a lot.

sarvarkhalimov
Автор

What do regular expressions do to the code ??

paulfanning