Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function oldBooks(input) {
- let book = input[0];
- let index = 0;
- let command;
- while(true) {
- command = input[++index];
- if (command === "No More Books" || command === book) {
- if (command === book) {
- console.log(`You checked ${--index} books and found it.`);
- } else {
- console.log(`The book you search is not here!\nYou checked ${--index} books.`);
- }
- return;
- }
- }
- }
- Решение с for:
- function oldBooks(input) {
- let book = input[0];
- for (let i = 1; i < Number.MAX_SAFE_INTEGER; i++) {
- let command = input[i];
- if (command === "No More Books" || command === book) {
- if (command === book) {
- console.log(`You checked ${--i} books and found it.`);
- } else {
- console.log(`The book you search is not here!\nYou checked ${--i} books.`);
- }
- return;
- }
- }
- }
Add Comment
Please, Sign In to add comment