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

id, title, challengeType, dashedName
id title challengeType dashedName
69272dcf1c24b44fd79137c3 Challenge 140: SCREAMING_SNAKE_CASE 28 challenge-140

--description--

Given a string representing a variable name, return the variable name converted to SCREAMING_SNAKE_CASE.

The given variable names will be written in one of the following formats:

  • camelCase
  • PascalCase
  • snake_case
  • kebab-case

In the above formats, words are separated by an underscore (_), a hyphen (-), or a new word starts with a capital letter.

To convert to SCREAMING_SNAKE_CASE:

  • Make all letters uppercase
  • Separate words with an underscore (_)

--hints--

toScreamingSnakeCase("userEmail") should return "USER_EMAIL".

assert.equal(toScreamingSnakeCase("userEmail"), "USER_EMAIL");

toScreamingSnakeCase("UserPassword") should return "USER_PASSWORD".

assert.equal(toScreamingSnakeCase("UserPassword"), "USER_PASSWORD");

toScreamingSnakeCase("user_id") should return "USER_ID".

assert.equal(toScreamingSnakeCase("user_id"), "USER_ID");

toScreamingSnakeCase("user-address") should return "USER_ADDRESS".

assert.equal(toScreamingSnakeCase("user-address"), "USER_ADDRESS");

toScreamingSnakeCase("username") should return "USERNAME".

assert.equal(toScreamingSnakeCase("username"), "USERNAME");

toScreamingSnakeCase("my_variable_name") should return "MY_VARIABLE_NAME".

assert.equal(toScreamingSnakeCase("my_variable_name"), "MY_VARIABLE_NAME");

--seed--

--seed-contents--

function toScreamingSnakeCase(variableName) {

  return variableName;
}

--solutions--

function toScreamingSnakeCase(variableName) {
  let temp = variableName.replace(/[-_]+/g, ' ');
  temp = temp.replace(/([a-z0-9])([A-Z])/g, '$1 $2');
  const words = temp.trim().split(/\s+/);
  return words.join('_').toUpperCase();
}