Skip to content

type error in the solution for exercise C.5.13 Soluঞon to: Heroes of the Silver Screen Part 5 #62

Open
@ghost

Description

Hello,

According to the book the solution could be :

films.foldLeft(0)((a, b) => a.imdbRating + b.imdbRating) / films.length

but a is a sort of accumelator so it do not have the property imdbRating.
The solution that works for me is :

allFilms.foldLeft(0:Double)((a,b) => a + b.imdbRating) / allFilms.length

I have to cast the 0 to Double otherwise the compiler thinks that 0 is a Int and imdbRating is a double and that will not work.

Roelof

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions