I got this sample data.
"array" : [
{"Id" : "1", "preferred" : false},
{"Id" : "1", "preferred" : true },
{"Id" : "2", "preferred" : false},
{"Id" : "2", "preferred" : false},]
And i would like to get out of it something like this.
"array2":[{"Id": 1, numOfTrue: 1, numOfFalse: 1},{"Id": 2, numOfTrue: 0, numOfFalse: 2}]
What i got so far is a way how to get unique id form initial array.
const unique = [...new Set(array.map(item => Id))];
Next step would be some forEach over array and comparing Id values and setting some counters for that boolean value. So before i dive into forEach solution i would like to ask if there is another way with using .filter() and .reduce() methods.
numOfTrueis the number of records with that id that have apreferred: truevalue and similarly fornumOfFalse.