Link to home
Start Free TrialLog in
Avatar of Simon Leung
Simon Leung

asked on

JavaScript / Angular query

Any idea what does the below coding perform ?
#1 this.movie.ratings.map(r => r.stars)
#2 .reduce((prev, curr) => prev + curr, 0);


get stars(): boolean[] {
        if (this.movie != null && this.movie.ratings != null) {
            let total = this.movie.ratings.map(r => r.stars)
                .reduce((prev, curr) => prev + curr, 0);
            let count = Math.round(total / this.movie.ratings.length);
            return Array(5).fill(false).map((value, index) => {
                return index < count;
            });
        }
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial