我需要从javascript(typescript)的数组中删除重复的或空的值(集合),如果在同一天有非空值的数据,如果所有的值(集合)在那天都是空的,我们应该保留一个值。
示例:
0: (2) ['2022-12-05', null] ---> Remove due to "Reason 1"
1: (2) ['2022-12-05', 2695.923015841] ---> Remain because it has a y value (on 5 Dec)
2: (2) ['2022-12-05', null] ---> Remove due to "Reason 1"
3: (2) ['2022-12-05', null] ---> Remove due to "Reason 1"
4: (2) ['2022-12-12', null] ---> Remove due to "Reason 1"
5: (2) ['2022-12-12', 3984.864626441] ---> Remain because it has a y value (on 12 Dec)
6: (2) ['2022-12-12', null] ---> Remove due to "Reason 1"
7: (2) ['2022-12-12', null] ---> Remove due to "Reason 1"
8: (2) ['2022-12-19', null] ---> Remove due to "Reason 2"
9: (2) ['2022-12-19', null] ---> Remove due to "Reason 2"
10: (2) ['2022-12-19', null] ---> Remove due to "Reason 2"
11: (2) ['2022-12-19', null] ---> Remain because no y value on this date
- 原因1**:数组的这个成员应该被删除,因为在同一个日期有一个空值(在x中指定)。
0: (2) [x: Date, y: value]
- 原因2**:这个成员应该被删除,因为我们有4个相同值的重复对象,我们只需要其中的一个。
预期结果:
它将是一个具有3个值(集)的数组。
0: (2) ['2022-12-05', 2695.923015841] ---> Remain because it has a y value
1: (2) ['2022-12-12', 3984.864626441] ---> Remain because it has a y value
2: (2) ['2022-12-19', null] ---> Remain because no y value on this date
2条答案
按热度按时间gcxthw6b1#
您可以使用单个循环来缩减数组,并检查
date
t1rydlwq2#