-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkey-groups.js
More file actions
30 lines (25 loc) · 910 Bytes
/
key-groups.js
File metadata and controls
30 lines (25 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* This script reads the flattened browser compat data
* and groups it by key segments.
*/
import bcdf from './data/bcdf.json' with { type: 'json' };
// Filter by a specific year
const year = 2017;
const filterByYear = (data) => {
const earliestReleaseDate =
data.support.sort((a, b) => a.release_date - b.release_date)[0].release_date;
return earliestReleaseDate != null
&& earliestReleaseDate.startsWith(year);
};
const forYear = bcdf.filter(filterByYear);
console.log(forYear.length);
// Group by key segment, eg "api.URL"
// and index of how many times it appears
const groups = forYear.reduce((acc, data) => {
const keySegments = data.key.split('.');
const key = keySegments.slice(0, 2).join('.');
const idx = acc.findIndex(group => group[0] === key);
idx === -1 ? acc.push([ key, 1 ]) : acc[idx][1]++;
return acc;
}, []).sort((a, b) => b[1] - a[1]);
console.log(groups);