Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3f3cd2a

Browse files
committed
Add a new question
1 parent 2c12e6c commit 3f3cd2a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

‎README.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ console.log(disemvowel('This website is for losers LOL!')); // 'Ths wbst s fr ls
275275

276276
```js
277277
const disemvowel = str => {
278+
// Let's use regular expressions (regex)
278279
return str.replace(/[aeiou]/gi, '');
279280
};
280281
```
@@ -2060,3 +2061,43 @@ const getNames = users => users.map(user => user.name);
20602061
---
20612062

20622063
**[⬆ 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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /