SHARE
TWEET

Untitled

a guest Aug 19th, 2019 31 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function findingABook(input) {
  2.     let book = input.shift();
  3.     let numberOfBooks = Number(input.shift());
  4.     let counter = 0;
  5.     let newBookName;
  6.     while (counter < numberOfBooks) {
  7.         let newBookName = input.shift();
  8.        
  9.         if ( newBookName===book) {
  10.             console.log(`You checked ${counter} books and found it.`)
  11.             break;
  12.         }
  13.         else{
  14.             counter++;
  15.         }
  16.        
  17.     }
  18.     if(newBookName!=book){
  19.         console.log(`The book you search is not here!
  20.         You checked ${counter} books.`);
  21.     }
  22.    
  23.  
  24.  
  25. }
  26. // findingABook(['The Spot','4','Hunger Games','Harry Potter','Torronto','Spotify']);
  27. // findingABook(['Troy','Stronger','Life Style','Troy']);
  28. findingABook(['Bourne','32','True Story','Forever','More Space','The Girl','Spaceship','Strongest','Profit','Tripple','Stella','The Matrix','Bourne']);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top