@@ -275,6 +275,7 @@ console.log(disemvowel('This website is for losers LOL!')); // 'Ths wbst s fr ls
275
275
276
276
``` js
277
277
const disemvowel = str => {
278
+ // Let's use regular expressions (regex)
278
279
return str .replace (/ [aeiou] / gi , ' ' );
279
280
};
280
281
```
@@ -2060,3 +2061,43 @@ const getNames = users => users.map(user => user.name);
2060
2061
---
2061
2062
2062
2063
** [ ⬆ Back to Top] ( #javascript-coding-challenges-for-beginners ) **
2064
+
2065
+ ## 58. Object Keys from snake_case to camelCase
2066
+
2067
+ Write a function that converts all the keys in an object from snake case to camel case.
2068
+
2069
+ ``` js
2070
+ const toCamel = obj => {
2071
+ // Your solution
2072
+ };
2073
+
2074
+ console .log (
2075
+ toCamel ({
2076
+ first_name: ' John' ,
2077
+ last_name: ' Rambo' ,
2078
+ favorite_movie: ' First Blood' ,
2079
+ })
2080
+ ); // {'firstName': 'John', 'lastName': 'Rambo', 'favoriteMovie': 'First Blood'}
2081
+ ```
2082
+
2083
+ <details ><summary >Solution</summary >
2084
+
2085
+ ``` js
2086
+ const toCamel = obj => {
2087
+ const result = {};
2088
+ for (const [key , value ] of Object .entries (obj)) {
2089
+ // Let's use regex capture groups
2090
+ const camelKey = key .replace (/ (_[a-z ] )/ gi , 1ドル =>
2091
+ 1ドル .replace (' _' , ' ' ).toUpperCase ()
2092
+ );
2093
+ result[camelKey] = value;
2094
+ }
2095
+ return result;
2096
+ };
2097
+ ```
2098
+
2099
+ </details >
2100
+
2101
+ ---
2102
+
2103
+ ** [ ⬆ Back to Top] ( #javascript-coding-challenges-for-beginners ) **
0 commit comments