This is the current output:
thisIsAString
ThisIsAString
this_is_a_string
this-is-a-string
This Is A String
thIs Is A strIng
THiS iS a STRiNG
Error
Looking for suggestions on how to evaluate with 2 case types. Been staring at this for hours and can't solve it. I imagine there are simpler ways to write this entire Kata, but I'm just starting with coding and don't have all the tools/skills yet to pull from. Would appreciate addressing my long drawn out solution instead of rewriting the entire thing.
Thanks for any help!
const makeCase = function(input, style) {
let result = '';
let styleTypes = [];
if (typeof style === 'string') {
styleTypes.push(style);
} else if (typeof style !== 'string') {
for (let i = 0; i < style.length; i++) {
styleTypes.push(style[i]);
}
}
for (let i = 0; i < styleTypes.length; i++) {
if (style === 'camel') {
result = camelCase(input);
} else if (style === 'pascal') {
result = pascalCase(input);
} else if (style === 'snake') {
result = snakeCase(input);
} else if (style === 'kebab') {
result = kebabCase(input);
} else if (style === 'title') {
result = titleCase(input);
} else if (style === 'vowel') {
result = vowelCase(input);
} else if (style === 'consonant') {
result = consonantCase(input);
} else if (style === 'upper') {
result = upperCase(input);
} else if (style === 'lower') {
result = lowerCase(input);
} else {
result = 'Error';
}
}
return result;
}
const camelCase = function(string) {
let newString = '';
for (i = 0; i < string.length; i++) {
if (string[i] === ' ') {
i++;
newString += string[i].toUpperCase();
} else {
newString += string[i];
}
}
return newString;
}
const pascalCase = function(string) {
let newString = '';
for (i = 0; i < string.length; i++) {
if (i === 0) {
newString += string[0].toUpperCase();
} else if (string[i] === ' ') {
i++;
newString += string[i].toUpperCase();
} else {
newString += string[i];
}
}
return newString;
}
const snakeCase = function(string) {
let newString = '';
for (i = 0; i < string.length; i++) {
if (string[i] === ' ') {
newString += '_';
} else {
newString += string[i];
}
}
return newString;
}
const kebabCase = function(string) {
let newString = '';
for (let i = 0; i < string.length; i++) {
if (string[i] === ' ') {
newString += '-';
} else {
newString += string[i];
}
}
return newString;
}
const titleCase = function(string) {
let newString = '';
string.toLowerCase();
for (let i = 0; i < string.length; i++) {
if (i === 0) {
newString += string[i].toUpperCase();
} else if (string[i] === ' ') {
newString += ' ' + string[i + 1].toUpperCase();
i++;
} else {
newString += string[i];
}
}
return newString;
}
const vowelCase = function(string) {
let newString = '';
for (let i = 0; i < string.length; i++) {
if (string[i] === 'a' ||
string[i] === 'e' ||
string[i] === 'i' ||
string[i] === 'o' ||
string[i] === 'u' ) {
newString += string[i].toUpperCase();
} else {
newString += string[i];
}
}
return newString;
}
const consonantCase = function(string) {
let newString = '';
for (let i = 0; i < string.length; i++) {
if (string[i] !== 'a' &&
string[i] !== 'e' &&
string[i] !== 'i' &&
string[i] !== 'o' &&
string[i] !== 'u' ) {
newString += string[i].toUpperCase();
} else {
newString += string[i];
}
}
return newString;
}
const upperCase = function(string) {
let newString = '';
newString = string.toUpperCase();
return newString;
}
const lowerCase = function(string) {
let newString = '';
newString = string.toLowerCase();
return newString;
}
//Test console logs for each function
// console.log(camelCase('this is a string'));
// console.log(pascalCase('this is a string'));
// console.log(snakeCase('this is a string'));
// console.log(kebabCase('this is a string'));
// console.log(titleCase('this is a string'));
// console.log(vowelCase('this is a string'));
// console.log(consonantCase('this is a string'));
// console.log(upperCase('this is a string'));
// console.log(lowerCase('this is a string'));
//Console logs for expected result
console.log(makeCase("this is a string", "camel"));
console.log(makeCase("this is a string", "pascal"));
console.log(makeCase("this is a string", "snake"));
console.log(makeCase("this is a string", "kebab"));
console.log(makeCase("this is a string", "title"));
console.log(makeCase("this is a string", "vowel"));
console.log(makeCase("this is a string", "consonant"));
console.log(makeCase("this is a string", ["upper", "snake"]));
//Expected output
// thisIsAString
// ThisIsAString
// this_is_a_string
// this-is-a-string
// This Is A String
// thIs Is A strIng
// THiS iS a STRiNG
// THIS_IS_A_STRING