Questions
Comma-separated strings are a common data format. How would you create an array of elements when given one?
The
\\bspecial character can define a word boundary, and\\Bmatches on a nonword boundary. Define a regular expression that will find all occurrences of the word “fun” in the string and replace them with “power”:“The fun of functions is that they are functional.” Create code to get today’s date, modify it by a week, and print out the new date.
Given a number of 34.44, how would you round the number down? Round it up?
Given a string like the following, use pattern match and replace to turn all punctuation into commas, and then load as an array and print out each value:
var str = "apple.orange-strawberry,lemon-.lime";
Answers are provided in the appendix.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access