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 8552938

Browse files
committed
Add a question
1 parent d9f357f commit 8552938

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,3 +1603,34 @@ const cakes = (recipe, available) => {
16031603
---
16041604

16051605
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**
1606+
1607+
## 48. Count characters in your string
1608+
1609+
Write a function that counts the frequency of all the characters in a given string.
1610+
1611+
```js
1612+
const count = string => {
1613+
// Your solution
1614+
}
1615+
1616+
console.log(count('')); // {}
1617+
console.log(count('aba')); // { a: 2, b: 1 }
1618+
```
1619+
1620+
<details><summary>Solution</summary>
1621+
1622+
```js
1623+
const count = string => {
1624+
const result = {};
1625+
for (let char of string) {
1626+
result[char] = (result[char] || 0) + 1;
1627+
}
1628+
return result;
1629+
}
1630+
```
1631+
1632+
</details>
1633+
1634+
---
1635+
1636+
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

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