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

id, title, challengeType, dashedName
id title challengeType dashedName
69b58ce40693f140c84c8559 Challenge 240: Palindrome Characters 28 challenge-240

--description--

Given a string, determine if it's a palindrome and return the middle character (if it's odd length) or middle two characters (if it's even).

  • A palindrome is a string that is the same forward and backward.
  • If it's not a palindrome, return "none".

--hints--

palindromeLocator("racecar") should return "e".

assert.equal(palindromeLocator("racecar"), "e");

palindromeLocator("level") should return "v".

assert.equal(palindromeLocator("level"), "v");

palindromeLocator("freecodecamp") should return "none".

assert.equal(palindromeLocator("freecodecamp"), "none");

palindromeLocator("noon") should return "oo".

assert.equal(palindromeLocator("noon"), "oo");

palindromeLocator("11100111") should return "00".

assert.equal(palindromeLocator("11100111"), "00");

--seed--

--seed-contents--

function palindromeLocator(str) {

  return str;
}

--solutions--

function palindromeLocator(str) {
  if (str !== str.split("").reverse().join("")) return "none";

  const mid = Math.floor(str.length / 2);
  return str.length % 2 === 1 ? str[mid] : str[mid - 1] + str[mid];
}