-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.js
More file actions
47 lines (39 loc) · 1013 Bytes
/
objects.js
File metadata and controls
47 lines (39 loc) · 1013 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const keys = (obj) => {
return Object.keys(obj);
};
const values = (obj) => {
// return Object.values(obj) best solution!
return Object.keys(obj).map(value => obj[value]);
};
const mapObject = (obj, cb) => {
const newObj = {};
Object.keys(obj).map(key => newObj[key] = obj[key]);
return cb(newObj);
};
const pairs = (obj) => {
const newArr = [];
Object.keys(obj).map((key, i, arr) => newArr.push([arr[i], obj[key]]));
return newArr;
};
/* STRETCH PROBLEMS */
const invert = (obj) => {
const newObj = {};
Object.keys(obj).map((key, i, arr) => newObj[obj[key]] = arr[i]);
return newObj;
};
const defaults = (obj, defaultProps) => {
// Fill in undefined properties that match properties on the `defaultProps` parameter object.
// Return `obj`.
// http://underscorejs.org/#defaults
const defObj = {};
Object.keys(obj).map((key, i, arr) => defObj[obj]);
};
/* eslint-enable no-unused-vars */
module.exports = {
keys,
values,
mapObject,
pairs,
invert,
defaults,
};