Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let favouriteBook = input.shift();
- let numBook = Number(input.shift());
- let counter = 0;
- let isBookFound = false;
- while (counter < numBook) {
- let nextBook = input.shift();
- if (nextBook == favouriteBook) {
- isBookFound = true;
- console.log(`You checked ${counter} books and found it.`)
- break;
- }
- counter++;
- nextBook = input.shift();
- }
- if (!isBookFound) {
- console.log(`The book you search is not here!`);
- console.log(`You checked ${numBook} books.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement