Published
Edited
Aug 14, 2018
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
solution1 = (keys, obj) => {
return Object.keys(obj).reduce((acc, x) => {
return keys.includes(x) ? {...acc, [x]: obj[x]} : acc
}, {})
}
Insert cell
solution1(keys, obj)
Insert cell
solution1(['MISSING', 'b'], obj)
Insert cell
Insert cell
Insert cell
solution2 = (keys, obj) => {
return keys.reduce((acc, k) => {
const data = obj.hasOwnProperty(k) ? {[k]: obj[k]} : {}
return {...acc, ...data}
}, {})
}
Insert cell
solution2(keys, obj)
Insert cell
solution2(['MISSING', 'b'], obj)
Insert cell
Insert cell
Insert cell
solution3 = (keys, obj) => Object.entries(obj)
.filter(([k, v]) => keys.includes(k))
.reduce((acc, [k, v]) => ({...acc, [k]: v}), {})
Insert cell
solution3(keys, obj)
Insert cell
solution3(['MISSING', 'b'], obj)
Insert cell
Insert cell
Insert cell
Insert cell
R.pick(keys, obj)
Insert cell
R.pick(['MISSING', 'b'], obj)
Insert cell
R.pickAll(['MISSING', 'b'], obj)
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