count-vowels.sh — zsh
strings

Return the number of characters in s that are ASCII vowels (a, e, i, o, u) in either case.

Input / output

  • Input: s: string
  • Output: integer count

Examples

  1. "hello" returns 2.
  2. "AEIOU" returns 5.

Constraints

  • 0 <= s.length <= 100,000
  • Only the ten ASCII vowel characters count

Follow-up How would locale-aware vowel classification change the contract and tests?

Examples
Example 1
Input: s = "hello"
Output: 2
Example 2
Input: s = "AEIOU"
Output: 5
Example 3
Input: s = "xyz"
Output: 0
🔒 5 hidden
Running will execute all 8 cases, including 5 hidden ones.