Javascript; Compress array with distinct values/count

  arrays, count, distinct, javascript

I got myself a puzzle i’m working on. I got a multi-dimensional array in Javascript that looks like this;
Each feature has an ID, a date(string) and a state

For example;

Features = [
    [1, "20200503", "Active"],
    [2, "20200503", "Closed"],
    [2, "20200503", "Closed"],
    [2, "20200502", "Closed"],
    [2, "20200501", "Active"],
    [2, "20200430", "Active"],
    [2, "20200430", "Active"],
    [3, "20200503", "New"],
    [3, "20200502", "New"],
];

I want to compress this array into a new one where I want this as a result;

Features = [
    [1, 1, "Active"],
    [2, 3, "Closed"],
    [2, 3, "Active"],
    [3, 2, "New"],
];

I would like to do a distinct on the ID and the state and count the date.

Is it somehow possible to do this in Javascript?

Source: Ask Javascript Questions

LEAVE A COMMENT