Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findingABook(input) {
- let book = input.shift();
- let numberOfBooks = Number(input.shift());
- let counter = 0;
- let newBookName;
- while (counter < numberOfBooks) {
- let newBookName = input.shift();
- if ( newBookName===book) {
- console.log(`You checked ${counter} books and found it.`)
- break;
- }
- else{
- counter++;
- }
- }
- if(newBookName!=book){
- console.log(`The book you search is not here!
- You checked ${counter} books.`);
- }
- }
- // findingABook(['The Spot','4','Hunger Games','Harry Potter','Torronto','Spotify']);
- // findingABook(['Troy','Stronger','Life Style','Troy']);
- findingABook(['Bourne','32','True Story','Forever','More Space','The Girl','Spaceship','Strongest','Profit','Tripple','Stella','The Matrix','Bourne']);
Add Comment
Please, Sign In to add comment