Published
Edited
Apr 19, 2018
12 stars
Insert cell
Insert cell
input = ['cats', 'dogs', 'cats', 'kittens', 'kitties', 'kittens', 'dogs', 'dogs', 'cats', 'bad dogs']
Insert cell
Insert cell
// Translate {a:b} into [[a, b]]
Object.entries(input.reduce((memo, i) => {
memo[i] = (memo[i] || 0) + 1;
return memo;
}, {}))
.sort((a, b) => b[1] - a[1])
.slice(0, 3)
.map(a => a[0])
Insert cell
Insert cell
[input]
.map(i => i.reduce((memo, i) => {
memo[i] = (memo[i] || 0) + 1;
return memo;
}, {}))
.map(i => Object.entries(i))
.map(i => i.sort((a, b) => b[1] - a[1]))
.map(i => i.slice(0, 3))
.map(i => i.map(a => a[0]))
[0]
Insert cell
Insert cell
[input]
.map(i => i.reduce((memo, i) => {
memo[i] = (memo[i] || 0) + 1;
return memo;
}, {}))
.map(i => Object.entries(i))[0]
.sort((a, b) => b[1] - a[1])
.slice(0, 3)
.map(a => a[0])
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more