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.7 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6814d8e1516e86b171929de4 Challenge 1: Vowel Balance 28 challenge-1

--description--

Given a string, determine whether the number of vowels in the first half of the string is equal to the number of vowels in the second half.

  • The string can contain any characters.
  • The letters a, e, i, o, and u, in either uppercase or lowercase, are considered vowels.
  • If there's an odd number of characters in the string, ignore the center character.

--hints--

isBalanced("racecar") should return true.

assert.isTrue(isBalanced("racecar"));

isBalanced("Lorem Ipsum") should return true.

assert.isTrue(isBalanced("Lorem Ipsum"));

isBalanced("Kitty Ipsum") should return false.

assert.isFalse(isBalanced("Kitty Ipsum"));

isBalanced("string") should return false.

assert.isFalse(isBalanced("string"));

isBalanced(" ") should return true.

assert.isTrue(isBalanced(" "));

isBalanced("abcdefghijklmnopqrstuvwxyz") should return false.

assert.isFalse(isBalanced("abcdefghijklmnopqrstuvwxyz"));

isBalanced("123A#b!E&*456-o.U") should return true.

assert.isTrue(isBalanced("123A#b!E&*456-o.U"));

--seed--

--seed-contents--

function isBalanced(s) {

  return s;
}

--solutions--

function isBalanced(s) {
  const vowels = 'aeiou';
  const half = Math.floor(s.length / 2);

  let firstHalf = s.slice(0, half);
  let secondHalf = s.length % 2 === 0 ? s.slice(half) : s.slice(half + 1);

  const countVowels = str =>
    str
      .toLowerCase()
      .split('')
      .filter(c => vowels.includes(c))
      .length;

  return countVowels(firstHalf) === countVowels(secondHalf);
}