-
Notifications
You must be signed in to change notification settings - Fork 0
View Examples
Sebastian Raff edited this page Sep 30, 2017
·
3 revisions
These examples operate on data created by create-example-data.js.
Map
if (this.type === 'Moon') {
emit({name: this.name, planet: this.planet})
}Reduce
return result.sort((a, b) => a.name.localeCompare(b.name))Map
if (this.type === 'Moon') {
emit({
name: this.name,
diameter: this.diameter,
planet: this.planet
})
}Reduce
const out = {};
result.forEach(moon => {
if (!out[moon.planet] || moon.diameter > out[moon.planet].diameter) {
out[moon.planet] = {name: moon.name, diameter: moon.diameter}
}
});
return out;Map
if (this.type === 'Moon') {
emit(this.planet)
}Reduce
return result.reduce((acc, curr) => {
acc[curr] = (acc[curr] || 0) + 1
return acc
}, {})Map
if (this.type === 'Moon') {
emit(this.planet)
}Reduce
const count = result.reduce((acc, curr) => {
acc[curr] = (acc[curr] || 0) + 1
return acc
}, {})
return Object.keys(count)
.map(planet => ({planet, moons: count[planet]}))
.sort((a, b) => a.moons < b.moons)mqttDB copyright (c) 2017 Sebastian Raff. MIT License