Advertisement
Guest User

Untitled

a guest
Feb 14th, 2020
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3.     let favouriteBook = input.shift();
  4.     let numBook = Number(input.shift());
  5.  
  6.     let counter = 0;
  7.     let isBookFound = false;
  8.  
  9.  
  10.     while (counter < numBook) {
  11.         let nextBook = input.shift();
  12.         if (nextBook == favouriteBook) {
  13.             isBookFound = true;
  14.             console.log(`You checked ${counter} books and found it.`)
  15.             break;
  16.         }
  17.         counter++;
  18.         nextBook = input.shift();
  19.     }
  20.     if (!isBookFound) {
  21.         console.log(`The book you search is not here!`);
  22.         console.log(`You checked ${numBook} books.`);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement