@@ -5,34 +5,61 @@ const keys = (obj) => {
55 // Retrieve all the names of the object's properties.
66 // Return the keys as strings in an array.
77 // Based on http://underscorejs.org/#keys
8+ return Object . keys ( obj ) ;
89} ;
910
1011const values = ( obj ) => {
1112 // Return all of the values of the object's own properties.
1213 // Ignore functions
1314 // http://underscorejs.org/#values
15+ const vals = Object . keys ( obj ) . map ( ( key ) => {
16+ return obj [ key ] ;
17+ } ) ;
18+ return vals ;
1419} ;
1520
1621const mapObject = ( obj , cb ) => {
1722 // Like map for arrays, but for objects. Transform the value of each property in turn.
1823 // http://underscorejs.org/#mapObject
24+ Object . keys ( obj ) . forEach ( key => ( obj [ key ] = cb ( obj [ key ] ) ) ) ;
25+ return obj ;
1926} ;
2027
2128const pairs = ( obj ) => {
2229 // Convert an object into a list of [key, value] pairs.
2330 // http://underscorejs.org/#pairs
31+ const keyValue = ( Object . keys ( obj ) . map ( key => ( [ key , obj [ key ] ] ) ) ) ;
32+ return keyValue ;
2433} ;
25-
2634const invert = ( obj ) => {
2735 // Returns a copy of the object where the keys have become the values and the values the keys.
2836 // Assume that all of the object's values will be unique and string serializable.
2937 // http://underscorejs.org/#invert
38+ // Object.keys(obj).forEach((key) => {
39+ // const newKey = obj[key];
40+ // obj[newKey] = key;
41+ // delete obj[key];
42+ // });
43+ // return obj;
44+ Object . keys ( obj ) . forEach ( ( key ) => {
45+ const newKey = obj [ key ] ;
46+ obj [ newKey ] = key ;
47+ delete obj [ key ] ;
48+ } ) ;
49+ return obj ;
3050} ;
3151
3252const defaults = ( obj , defaultProps ) => {
3353 // Fill in undefined properties that match properties on the `defaultProps` parameter object.
3454 // Return `obj`.
3555 // http://underscorejs.org/#defaults
56+ Object . keys ( defaultProps ) . forEach ( ( key ) => {
57+ if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) {
58+ return ;
59+ }
60+ obj [ key ] = defaultProps [ key ] ;
61+ } ) ;
62+ return obj ;
3663} ;
3764
3865/* eslint-enable no-unused-vars */
0 commit comments