我试图解决合并两个对象数组的问题,所以我写了一个非常简单的函数
function mergeShowtimes(movies) {
var existing_halls = [];
return movies.reduce(function(acc, movie) {
var movies_with_hallid,
movies_seats;
if (existing_halls.indexOf(movie.hallId) === -1) {
movies_with_hallid = _.filter(movies, function(filter_movie) {
return movie.hallId === filter_movie.hallId;
});
movies_seats = _.map(movies_with_hallid, 'seats');
movie.seats = _.union.apply(this, movies_seats);
acc.push(movie);
existing_halls.push(movie.hallId);
}
return acc;
}, []);
}
问题是,每当我检查movie
和movie.seats
的值时,字段'席位' movie
中的movie.seats
为空,但由于某种原因,acc.push(movie);
不是
如果我删除pip is not an internal or external command nor is it a running program or batch file.
,一切都会按计划开始工作
我做错了什么?
感谢您的反馈!