Working with Strings - Part 3
17.1
Below is the bookCategories variable that stores a string of categories. Each category is separated with a semicolon, for example, in a string "science;computing", 'science' and 'computing' are separate categories.
Write a function called logBookCategories that takes a string of categories separated with semicolons, and logs each category to the console (as separate strings).
Code:
Expected output:
17.2
Now, the opposite. Each book from the books array has the keywords property.
Write a function called getKeywordsAsString that takes the books array as an argument, collects keywords from each book, removes duplicates, and then joins them to create a single string where keywords are separated by a semicolon.
Code:
Expected output:
17.3
Below is the bookChapters array that contains inner arrays. Each inner array consists of a chapter's title, and the number of a page, for example, in ['The Basics', 14], 'The Basics' is the chapter's title, and 14 is the number of a page.
Write a function called logBookChapters that takes an array of arrays (like bookChapters) as an argument, and logs each chapter's name to the console together with the page number. The page number should be separated from the chapter's name with underscores (take a look at the example below).
Use the padEnd method.
Code:
Expected output: