计算大胃王小明吃苹果数量.(根据时间戳得到区间,然后算出区间值之和)
计算大胃王小明吃苹果数量:
已知小明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
怎么做呀,我的思路是遍历元素判断是否符合条件。 取出有用的值放入新数组中用来求和,然后写不出来了,谢谢大佬解答
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
答案应该是58338吧
写了这的代码,你看下
打印结果:苹果数: 58338
这个其实是