This is my method, it was returning the same string as the input.
for ex: toggleEveryCharCases(‘character’) => ‘character’
Please answer me guys…
export function toggleEveryCharCases(str: string): string {
const strArr = str.split('');
for (let i = 0; i < strArr.length; i++) {
if (strArr[i] >= 'A' && strArr[i] <= 'Z') strArr[i] = strArr[i].toLowerCase();
else if (strArr[i] >= 'a' && strArr[i] <= 'z') strArr[i] = strArr[i].toUpperCase();
}
return strArr.join('');
}
I have tried my best. I want to get the char case togggled string
2
Answers
It does work as expected.
you can simplify the code to be
Here’s correct