⛰️ Hi community,
I need to group an array of objs by their boolean
Data
In these simplify example i have data (an array of objs) where every objet has a boolean and i need to group it by the information in the boolean.
- "R" = Right
- "L" = Left
Data
const data =
[
{id: 3337, score: 75, date: '2000-02-02T07:25:00.000Z', boolean: "R"},
{id: 4337, score: 65, date: '2000-02-02T07:25:15.000Z', boolean: "L"},
{id: 3336, score: 30, date: '2012-06-02T08:24:00.000Z', boolean: "R"},
{id: 4336, score: 32, date: '2012-06-02T08:24:15.000Z', boolean: "L"},
{id: 3335, score: 25, date: '2020-08-02T09:23:00.000Z', boolean: "R"},
{id: 4335, score: 30, date: '2020-08-02T09:23:15.000Z', boolean: "L"},
{id: 2234, score: 85, date: '2018-08-02T12:20:00.000Z', boolean: "R"},
{id: 4234, score: 80, date: '2018-08-02T12:20:12.000Z', boolean: "L"},
{id: 1534, score: 85, date: '2016-08-02T10:30:00.000Z', boolean: "R"},
{id: 4534, score: 88, date: '2016-08-02T10:30:15.000Z', boolean: "L"},
{id: 3884, score: 85, date: '2019-08-02T11:18:00.000Z', boolean: "R"},
{id: 4884, score: 79, date: '2019-08-02T11:18:15.000Z', boolean: "L"},
{id: 6534, score: 25, date: '2012-08-02T13:01:00.000Z', boolean: "R"},
{id: 4534, score: 22, date: '2012-08-02T13:05:00.000Z', boolean: "L"}
],
Expected Output
const result =
[
[
{id: 3337, score: 75, date: '2000-02-02T07:25:00.000Z', boolean: "R"},
{id: 3336, score: 30, date: '2012-06-02T08:24:00.000Z', boolean: "R"},
{id: 3335, score: 25, date: '2020-08-02T09:23:00.000Z', boolean: "R"},
{id: 2234, score: 85, date: '2018-08-02T12:20:00.000Z', boolean: "R"},
{id: 1534, score: 85, date: '2016-08-02T10:30:00.000Z', boolean: "R"},
{id: 3884, score: 85, date: '2019-08-02T11:18:00.000Z', boolean: "R"},
{id: 6534, score: 25, date: '2012-08-02T13:01:00.000Z', boolean: "R"}
],
[
{id: 4337, score: 65, date: '2000-02-02T07:25:15.000Z', boolean: "L"},
{id: 4336, score: 32, date: '2012-06-02T08:24:15.000Z', boolean: "L"},
{id: 4335, score: 30, date: '2020-08-02T09:23:15.000Z', boolean: "L"},
{id: 4234, score: 80, date: '2018-08-02T12:20:12.000Z', boolean: "L"},
{id: 4534, score: 88, date: '2016-08-02T10:30:15.000Z', boolean: "L"},
{id: 4884, score: 79, date: '2019-08-02T11:18:15.000Z', boolean: "L"},
{id: 4534, score: 22, date: '2012-08-02T13:05:00.000Z', boolean: "L"}
]
]
I think the answer would be with a map, sort it out and the push it, right? . But i don't have any clue how to do it.
Thanks a lot !