https://github.com/skyv26/letter-frequency
Given a string, calculate the frequency of each character. All characters should be counted. This includes lower and upper case letters, digits, whitespace, special characters, or any other distinct characters.
https://github.com/skyv26/letter-frequency
coding-challenge coding-interviews javascript
Last synced: 26 days ago
JSON representation
Given a string, calculate the frequency of each character. All characters should be counted. This includes lower and upper case letters, digits, whitespace, special characters, or any other distinct characters.
- Host: GitHub
- URL: https://github.com/skyv26/letter-frequency
- Owner: skyv26
- Created: 2023-01-20T08:26:36.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-20T08:29:10.000Z (over 2 years ago)
- Last Synced: 2025-02-10T21:35:28.882Z (3 months ago)
- Topics: coding-challenge, coding-interviews, javascript
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Letter Frequency
Given a string, calculate the frequency of each character.
All characters should be counted. This includes lower and upper case letters, digits, whitespace, special characters, or any other distinct characters.
Write a function to count the occurrences of each character in a given string.
The function should return a 2D array with each of the elements in the following form: `['char', freq]`. The character should be a string with a length of 1, and frequency is a number denoting the count.
For example, given the string "ab", your function should return `[['a', 1], ['b', 1]]`.
Submit a pull request to the main branch with your solution. Do not modify the tests. Once you have created a PR with passing tests, then you have successfully completed the exercise.
const string = 'My name is Aakash';
Output: [['M': 1], ['y': 1], ['n': 1], ['a': 3], ['m': 1], ['e': 1], ['i': 1], ['s': 2], ['A': 1], ['k': 1], ['h': 1], [' ': 3]]PseudoCode:
1. Create an empty object like {}.
2. I will iterate over the string and create an object of characters in string.
3. Iterate over the array and increment the count of the characters in array.
4. 'ABCAB' {'A': 2, 'B': 2, 'C': 1, }
5. as a output: [['A': 2], ['B': 2], ['C': 1]]