Bestsellers in the bookstore

Report a typo

We have a database of books, implemented as a list of books. A book is implemented as follows:

case class Book(title: String, authors: List[String], amountSold: Int, amountForSale: Int)

Define the function bestseller that returns the names of all authors who have amountSold / amountForSale >= 2.

Sample Input 1:

Book("Beach Read", List("Emily", "Henry"), 1000, 600)
Book("The Duke and I", List("Julia", "Quinn"), 100, 0)
Book("The Four Winds", List("Kristin", "Hannah"), 400, 100)
Book("It Ends with Us", List("Colleen", "Hoover"), 340, 200)

Sample Output 1:

Julia
Quinn
Kristin
Hannah
Write a program in Scala 3
def bestseller(books: List[Book]): List[String] =
for
// your code
yield ???
___

Create a free account to access the full topic