You want to map your movies, and you should return movie each time in loop. like this:
const movies = [
{
name: 'Rambo I', avgRating: 4.6659
},
{
name: 'Rambo II', avgRating: 3.158
},
{
name: 'Rambo III', avgRating: 3.956
}
];
const roundingAvgRating = (movies) => {
return movies.map((movie) => {
if (movie.avgRating) {
movie.avgRating = Math.round(movie.avgRating * 2) / 2;
}
return movie
});
}
also you don't need to make copy in map
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…