计算大胃王小明吃苹果数量:
已知小明2020-08-16至2020-09-15的吃苹果的数据如下:
*// steps[].step 苹果量
// steps[].timestamp 时间戳*
const steps = [{
step: 1753,
timestamp: 1597507200000
}, {
step: 1637,
timestamp: 1597593600000
}, {
step: 6216,
timestamp: 1597680000000
}, {
step: 6466,
timestamp: 1597766400000
}, {
step: 12998,
timestamp: 1597852800000
}, {
step: 7731,
timestamp: 1597939200000
}, {
step: 7115,
timestamp: 1598025600000
}, {
step: 3603,
timestamp: 1598112000000
}, {
step: 1659,
timestamp: 1598198400000
}, {
step: 3582,
timestamp: 1598284800000
}, {
step: 6979,
timestamp: 1598371200000
}, {
step: 4567,
timestamp: 1598457600000
}, {
step: 7639,
timestamp: 1598544000000
}, {
step: 9150,
timestamp: 1598630400000
}, {
step: 8565,
timestamp: 1598716800000
}, {
step: 6544,
timestamp: 1598803200000
}, {
step: 6316,
timestamp: 1598889600000
}, {
step: 15523,
timestamp: 1598976000000
}, {
step: 8254,
timestamp: 1599062400000
}, {
step: 13552,
timestamp: 1599148800000
}, {
step: 6163,
timestamp: 1599235200000
}, {
step: 6338,
timestamp: 1599321600000
}, {
step: 8508,
timestamp: 1599408000000
}, {
step: 4002,
timestamp: 1599494400000
}, {
step: 7501,
timestamp: 1599580800000
}, {
step: 5922,
timestamp: 1599667200000
}, {
step: 9635,
timestamp: 1599753600000
}, {
step: 7067,
timestamp: 1599840000000
}, {
step: 3878,
timestamp: 1599926400000
}, {
step: 4088,
timestamp: 1600012800000
}, {
step: 773,
timestamp: 1600099200000
}]
编写一个函数,将其中某个时间段的苹果数量进行小计,返回小计结果
示例:
输入:2020-09-01, 2020-09-07
返回:64654
怎么做呀,我的思路是遍历元素判断是否符合条件。 取出有用的值放入新数组中用来求和,然后写不出来了,谢谢大佬解答