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;
});
}
#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((
return index < count;
});
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.