Skip to content

[challenge] Count chars #65

@403-html

Description

@403-html

Challenge: Write a function called countChars that takes a string as input and returns an object that contains the count of each character in the string.

For example, if the input string is "Hello, world!", the function should return an object like this:

{
  H: 1,
  e: 1,
  l: 3,
  o: 2,
  ",": 1,
  " ": 1,
  w: 1,
  r: 1,
  d: 1,
  "!": 1
}

Instructions:

  • Write a function called countChars that takes a string as input and returns an object.
  • The object should contain the count of each character in the input string.
  • The function should be case-sensitive, so "H" and "h" should be counted as different characters.
  • If a character appears multiple times in the input string, the object should contain the correct count for that character.
  • Test your function by calling it with different input strings and printing the output to the console.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions