Question: In JavaScript: Write a function named compress(), that accepts a sentence containing blanks and punctuation and returns a string that is the sentence with all
In JavaScript: Write a function named compress(), that accepts a sentence containing blanks and punctuation and returns a string that is the sentence with all blanks and punctuation removed. This function must call isWhiteSpace() and isPunct(). // My isWhiteSpace() and isPunct() functions
function isWhiteSpace(str) { return str.replace(/^\s+|\s+$/g, '').length == 0; } isWhiteSpace (" ")
function isPunct(myChar){ var pattern = /[:;,.?!-'"(){}]/; return pattern.test(myChar); } isPunct("?")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
