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

id, title, challengeType, dashedName
id title challengeType dashedName
68f6587287ad1f4ad39b0c7e Challenge 92: Extension Extractor 28 challenge-92

--description--

Given a string representing a filename, return the extension of the file.

  • The extension is the part of the filename that comes after the last period (.).
  • If the filename does not contain a period or ends with a period, return "none".
  • The extension should be returned as-is, preserving case.

--hints--

getExtension("document.txt") should return "txt".

assert.equal(getExtension("document.txt"), "txt");

getExtension("README") should return "none".

assert.equal(getExtension("README"), "none");

getExtension("image.PNG") should return "PNG".

assert.equal(getExtension("image.PNG"), "PNG");

getExtension(".gitignore") should return "gitignore".

assert.equal(getExtension(".gitignore"), "gitignore");

getExtension("archive.tar.gz") should return "gz".

assert.equal(getExtension("archive.tar.gz"), "gz");

getExtension("final.draft.") should return "none".

assert.equal(getExtension("final.draft."), "none");

--seed--

--seed-contents--

function getExtension(filename) {

  return filename;
}

--solutions--

function getExtension(filename) {
  const lastDot = filename.lastIndexOf('.');
  
  if (lastDot === -1 || lastDot === filename.length - 1) {
    return "none";
  }
  
  return filename.slice(lastDot + 1);
}