Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
68f6587287ad1f4ad39b0c7f Challenge 93: Vowels and Consonants 28 challenge-93

--description--

Given a string, return an array with the number of vowels and number of consonants in the string.

  • Vowels consist of a, e, i, o, u in any case.
  • Consonants consist of all other letters in any case.
  • Ignore any non-letter characters.

For example, given "Hello World", return [3, 7].

--hints--

count("Hello World") should return [3, 7].

assert.deepEqual(count("Hello World"), [3, 7]);

count("JavaScript") should return [3, 7].

assert.deepEqual(count("JavaScript"), [3, 7]);

count("Python") should return [1, 5].

assert.deepEqual(count("Python"), [1, 5]);

count("freeCodeCamp") should return [5, 7].

assert.deepEqual(count("freeCodeCamp"), [5, 7]);

count("Hello, World!") should return [3, 7].

assert.deepEqual(count("Hello, World!"), [3, 7]);

count("The quick brown fox jumps over the lazy dog.") should return [11, 24].

assert.deepEqual(count("The quick brown fox jumps over the lazy dog."), [11, 24]);

--seed--

--seed-contents--

function count(str) {

  return str;
}

--solutions--

function count(str) {
  const vowels = 'aeiou';
  const consonants = 'bcdfghjklmnpqrstvwxyz';
  let v = 0, c = 0;

  for (let i=0; i<str.length; i++) {
    if (vowels.includes(str[i].toLowerCase())) {
      v++;
    }
    if (consonants.includes(str[i].toLowerCase())) {
      c++;
    }
  }

  return [v, c];
}