app.ts 904 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. function GetAllBooks() {
  2. let books = [
  3. {
  4. author: 'James Joyce',
  5. available: true,
  6. title: 'Ulysses',
  7. },
  8. {
  9. author: 'Ernest Hemingway',
  10. available: false,
  11. title: 'A farewall to arms',
  12. },
  13. {
  14. author: 'Maya Angelou',
  15. available: true,
  16. title: 'I know why the caged bird sings',
  17. },
  18. {
  19. author: 'Herman Melville',
  20. available: true,
  21. title: 'Moby Dick',
  22. }
  23. ];
  24. return books;
  25. }
  26. function LogFirstAvailable(books): void {
  27. const numberOfBooks: number = books.length;
  28. let firstAvailable: string = '';
  29. for (let currentBook of books) {
  30. if (currentBook.available) {
  31. firstAvailable = currentBook.title;
  32. break;
  33. }
  34. }
  35. console.log(`Total number of books: ${numberOfBooks}.`);
  36. console.log(`First available: ${firstAvailable}.`);
  37. }
  38. const allBooks = GetAllBooks();
  39. LogFirstAvailable(allBooks);