14
rated 0 times
[
21]
[
7]
/ answers: 1 / hits: 10438
/ 5 Years ago, thu, october 17, 2019, 12:00:00
I have an array of objects having a boolean field X. [{..., x: true, y: 3, ...]
I need to aggregate this array, in order to obtain a value, true
(or false
), if all values of x
are correspondingly true
(or false
), otherwise undefined
... and a sum of y
's...
is that possible to use the reduce
Array function, groupby by underscorejs, or another one for this purpose?
ex:
[
{a:'titi', x: true, y: 3},
{a:'toto', x: false, y: 6}
]
result
{x: undefined, y: 9}
More From » arrays