Skip to content

Commit 72f42bc

Browse files
committed
Completed stretch goal challenges
1 parent 3cc7074 commit 72f42bc

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/objects.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,23 @@ const invert = (obj) => {
3636
// Returns a copy of the object where the keys have become the values and the values the keys.
3737
// Assume that all of the object's values will be unique and string serializable.
3838
// http://underscorejs.org/#invert
39+
const clone = {};
40+
const objKeys = Object.keys(obj);
41+
const objValues = Object.values(obj);
42+
objValues.forEach((key, i) => clone[key] = objKeys[i]);
43+
return clone;
3944
};
4045

4146
const defaults = (obj, defaultProps) => {
4247
// Fill in undefined properties that match properties on the `defaultProps` parameter object.
4348
// Return `obj`.
4449
// http://underscorejs.org/#defaults
50+
Object.keys(defaultProps).forEach((key) => {
51+
if (!Object.hasOwnProperty.call(obj, key)) {
52+
obj[key] = defaultProps[key];
53+
}
54+
});
55+
return obj;
4556
};
4657

4758
/* eslint-enable no-unused-vars */

0 commit comments

Comments
 (0)