Count the Letters and Digits

Published by Helen Yu in

Write a function that takes a string and calculates the number of letters and digits within it. Return the result as an array.

Examples

countAll("Hello World") ➞ array("LETTERS" =>  10, "DIGITS" => 0)

countAll("H3ll0 Wor1d") ➞ array("LETTERS" =>  7, "DIGITS" => 3)

countAll("149990") ➞ array("LETTERS" => 0, "DIGITS" => 6)

Notes

  • Tests contain only alphanumeric characters.
  • Spaces are not letters.
  • All tests contain valid strings.
Watch a quick demo on how Edabit works.