@@ -5,35 +5,40 @@ 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- const newArr = [ ] ;
9- for ( let i = 0 ; i < obj . length ; i ++ ) {
10- newArr . push ( obj [ i ] ) ;
11- }
12- return newArr ;
8+ const key = Object . keys ( obj ) ;
9+ return key ;
1310} ;
1411
1512const values = ( obj ) => {
1613 // Return all of the values of the object's own properties.
1714 // Ignore functions
1815 // http://underscorejs.org/#values
19- // const val = Object.values(obj);
20- // return val;
16+ const val = Object . values ( obj ) ;
17+ return val ;
2118} ;
2219
2320const mapObject = ( obj , cb ) => {
2421 // Like map for arrays, but for objects. Transform the value of each property in turn.
2522 // http://underscorejs.org/#mapObject
23+
2624 // const map = Object.Map(obj, function(val, key) {
2725 // cb();
2826 // });
2927 // return map;
28+
29+ const key = keys ( obj ) ; // use
30+ const val = values ( obj ) ;
31+ for ( let i = 0 ; i < key . length ; i ++ ) {
32+ obj [ key [ i ] ] = cb ( val [ i ] ) ;
33+ }
34+ return obj ;
3035} ;
3136
3237const pairs = ( obj ) => {
3338 // Convert an object into a list of [key, value] pairs.
3439 // http://underscorejs.org/#pairs
35- // const pair = Object.entries(obj);
36- // return pair;
40+ const pair = Object . entries ( obj ) ;
41+ return pair ;
3742} ;
3843
3944/* STRETCH PROBLEMS */
0 commit comments