一个Array<Model>,比如
[{
" Items": [{
"RoomNum": 2
}, {
"RoomNum": 6
}],
"Dates": {
"From": "2018-05-21T16:00:00.000Z",
"To": "2018-05-26T16:00:00.000Z"
}
}, {
" Items": [{
"RoomNum": 3
}],
"Dates": {
"From": "2018-05-25T16:00:00.000Z",
"To": "2018-05-27T16:00:00.000Z"
}
}]
differenceInDays
用的date-fns.js
来获取from和to的差值(天数)
现在我想获取
(items.RoomNum * differenceInDays(item.TravelDates.To,item.TravelDates.From))
+(items.RoomNum * differenceInDays(item.TravelDates.To,item.TravelDates.From))...
举个例子,我想获取
2*5 + 6*5 +3*2
我应该怎么写
private buildNightNum(
groups: Dictionary<Model[]>,
item: string
) {
let differenceFromTo = groups[item]
.filter(t => t.Dates)
.reduce(
(a, b) => a + differenceInDays(b.Dates.To, b.Dates.From),
0
);
let roomNum = groups[item]
.filter(t => t.Items.filter(s => s.RoomNum))
.reduce(
(a, b) =>
a +
b.Items.filter(s => s.RoomNum)
.map(s => s.RoomNum)
.reduce((c, d) => c + d, 0),
0
);
return differenceFromTo* roomNum ;
}