This is code is good enough to pass on the unit tests. However, I am not satisfied with the design/approach. It seems to be particularized too much for the exercise purpose. How would you refactor this with Regular Expressions?
function sentensify(str) {
// Only change code below this line
if (str.includes(".")) {
let arrStr = str.split(".");
let newStr = arrStr.join(" ");
return newStr;
}
else if (str.includes("-")) {
let arrStr = str.split("-");
let newStr = arrStr.join(" ");
return newStr;
}
else {
let arrStr = str.split(",");
let newStr = arrStr.join(" ");
return newStr;
}
}
console.log(sentensify("The.force.is.strong.with.this.one"));
console.log(sentensify("May-the-force-be-with-you"));
console.log(sentensify("There,has,been,an,awakening"));
Browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
.
Challenge: Combine an Array into a String Using the join Method
Link to the challenge:
Thanks in advance