1. Mate Library is going through a tough time. It is very expensive to keep a librarian, so for the last 5 years, the library
1. Mate Library is going through a tough time. It is very expensive to keep a librarian, so for the last 5 years, the library has been operating without him. Readers come, take the books and go. But they put the books back not at the right place. In the good old days, all the books in the library were sorted alphabetically. Now the shelves are in chaos. Our robots from Mate Robot Factory come to the rescue. Should be fun? I don't think so. We'll remove all the books from the shelves, and sort them.
Write a sortBooks function that will accept an array of shelves (arrays of books) and returns an array of books sorted alphabetically.
Example:
sortBooks([ ['Going Over', 'Brazen'], ['The Enemy'], ['Followers', 'Belle Epoque'] ]); // ['Belle Epoque', 'Brazen', 'Followers', 'Going Over', 'The Enemy']
Second Question.
2.Implement the isJumping function, that accepts the number and returns the 'JUMPING' string if each digit in the number differs from its neighbor by 1 or 'NOT JUMPING' otherwise.
Please note:
- the input number is always positive;
- the difference between 9 and 0 is not 1;
- if there are identical digits nearby, the number is 'NOT JUMPING';
- if the number has only one digit it is 'JUMPING'.
For example: // single digit number isJumping(9); // 'JUMPING'
// 7 and 9 differ by 2 instead of 1 isJumping(79);
// 'NOT JUMPING' // difference between same digits is 0 isJumping(7889);
// 'NOT JUMPING' // all adjacent digits differ by 1
isJumping(23454); // 'JUMPING'
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Lets tackle both questions step by step First Question sortBooks function We need to write a function named sortBooks that will accept an array of she...See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started