Problem 31

Tally letters in string Recursion Challenge

Given a string, return an object where each key is a character from the string and its value is the number of times that character appears.

Function Signature

letterTally(str, obj)

Parameters

  • str — a string.
  • obj — (optional) an accumulator object, defaults to {}.

Output

Return an object mapping each unique character to its count.

Constraints

  • The function must use recursion.
  • The function should accept at most two arguments.

Examples

letterTally('potato')
→ {p: 1, o: 2, t: 2, a: 1}

letterTally('mississippi')
→ {m: 1, i: 4, s: 4, p: 2}  (4 unique keys)