Retrieve the Most Recently Borrowed Book

You are a librarian at a large library. The library's system records the titles of books that are checked out in the order they were borrowed. To keep track of the most recently borrowed book, you need to write a function that retrieves the last book title from an array of borrowed book titles.

Write a function named getLastBorrowedBook that takes one parameter books which is an array containing the titles of borrowed books. Return the last item in the books array.

Example 1

Input: getLastBorrowedBook(["The Great Gatsby", "1984", "To Kill a Mockingbird"]);
Output: "To Kill a Mockingbird"

Example 2

Input: getLastBorrowedBook(["Moby Dick", "Pride and Prejudice", "Hamlet"]);
Output: "Hamlet"

Example 3

Input: getLastBorrowedBook(["War and Peace", "Ulysses", "The Odyssey"]);
Output: "The Odyssey"

Are you stuck on this problem?

Get detailed, step-by-step solution and improve your JavaScript skills.

  • Detailed Explanation: Each solution comes with a comprehensive explanation, helping you understand the logic and concepts thoroughly.
  • Learn to Write Better Code: Even if you have written the code, discover ways to improve it and adopt best practices.
  • Save Time: Don’t waste hours struggling—get the solution and learn efficiently.
  • Lifetime Access: Get access to lifetime solutions for all problems available
Get the Solution

" I struggled with this problem for hours, but the solution provided here was clear and easy to follow. It helped me understand where I went wrong and improved my coding skills significantly." - Jane D.

If you're not satisfied, I offer a 7-day money-back guarantee.