-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path1-simple.js
More file actions
25 lines (18 loc) · 739 Bytes
/
Copy path1-simple.js
File metadata and controls
25 lines (18 loc) · 739 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
'use strict';
const partial = (fn, ...args) => (...rest) => fn(...args, ...rest);
const projection = (fields, obj) => Object.keys(obj)
.filter((field) => fields.includes(field))
.reduce((hash, key) => (hash[key] = obj[key], hash), {});
// Dataset
const persons = [
{ name: 'Marcus Aurelius', city: 'Rome', born: 121 },
{ name: 'Victor Glushkov', city: 'Rostov on Don', born: 1923 },
{ name: 'Ibn Arabi', city: 'Murcia', born: 1165 },
{ name: 'Mao Zedong', city: 'Shaoshan', born: 1893 },
{ name: 'Rene Descartes', city: 'La Haye en Touraine', born: 1596 },
];
// Usage
const p1 = partial(projection, ['name', 'born']);
const p2 = partial(projection, ['name']);
const data = persons.map(p1).map(p2);
console.dir(data);