【发布时间】:2019-07-14 19:31:20
【问题描述】:
我有[date, price]形式的价格/日期数据
let priceData = [
[1551052800000, 0.33739737955243454]
[1551139200000, 0.33628886196814234]
[1551225600000, 0.12674156277665535]
[1551312000000, 0.16847247989576378]
[1557792000000, 0.5650889670671049]
[1557878400000, 0.6003006017008962]
[1557964800000, 0.6438789432408669]
[1558051200000, 0.6684895789112406]
]
我想知道一种干净的方法来使用 lodash 或 map 或其他东西来获取这样的列表,并根据相同的日期将其组合起来......
// the data below may not be accurate, the point here is the structure
let exampleChuckedData = [
[
[1551052800000, 0.33739737955243454]
[1551139200000, 0.33628886196814234]
[1551225600000, 0.12674156277665535]
[1551312000000, 0.16847247989576378]
]
[
[1557792000000, 0.5650889670671049]
[1557878400000, 0.6003006017008962]
[1557964800000, 0.6438789432408669]
[1558051200000, 0.6684895789112406]
]
]
// Or more conceptually
// Grouped by same date
let exampleConceptData = [
[
['01/01/2019', 0.33739737955243454]
['01/01/2019', 0.33628886196814234]
['01/01/2019', 0.12674156277665535]
['01/01/2019', 0.16847247989576378]
]
[
['01/02/2019', 0.5650889670671049]
['01/02/2019', 0.6003006017008962]
['01/02/2019', 0.6438789432408669]
['01/02/2019', 0.6684895789112406]
]
]
我使用 moment 来满足我所有的日期格式化需求。也许有一种方法可以整合时刻来帮助解决这个问题,比如他们的*.isSame()
【问题讨论】:
标签: javascript datetime momentjs lodash