curriculum/challenges/english/blocks/daily-coding-challenges-javascript/694596b0585c11170ac7c7fb.md
Given a string representing a variable name, convert it to consonant case using the following rules:
a, e, i, o, u in any case) should be converted to lowercase.-) should be converted to underscores (_).toConsonantCase("helloworld") should return "HeLLoWoRLD".
assert.equal(toConsonantCase("helloworld"), "HeLLoWoRLD");
toConsonantCase("HELLOWORLD") should return "HeLLoWoRLD".
assert.equal(toConsonantCase("HELLOWORLD"), "HeLLoWoRLD");
toConsonantCase("_hElLO-WOrlD-") should return "_HeLLo_WoRLD_".
assert.equal(toConsonantCase("_hElLO-WOrlD-"), "_HeLLo_WoRLD_");
toConsonantCase("_~-generic_~-variable_~-name_~-here-~_") should return "_~_GeNeRiC_~_VaRiaBLe_~_NaMe_~_HeRe_~_".
assert.equal(toConsonantCase("_~-generic_~-variable_~-name_~-here-~_"), "_~_GeNeRiC_~_VaRiaBLe_~_NaMe_~_HeRe_~_");
function toConsonantCase(str) {
return str;
}
function toConsonantCase(str) {
const vowels = "aeiouAEIOU";
let result = "";
for (let char of str) {
if (char === "-") {
result += "_";
} else if (/[a-zA-Z]/.test(char)) {
if (vowels.includes(char)) {
result += char.toLowerCase();
} else {
result += char.toUpperCase();
}
} else {
result += char;
}
}
return result;
}