Skip to content

Instantly share code, notes, and snippets.

@AlvisonHunterArnuero
Created September 14, 2024 01:50
Show Gist options
  • Save AlvisonHunterArnuero/5722cdd72295665efc19e075859d7756 to your computer and use it in GitHub Desktop.
Save AlvisonHunterArnuero/5722cdd72295665efc19e075859d7756 to your computer and use it in GitHub Desktop.
const capitalize = (s: string): [string, string] => {
let arr01: string[] = [];
let arr02: string[] = [];
for (let i = 0; i < s.length; i++) {
if (i % 2 === 0) {
arr01.push(s[i].toUpperCase());
arr02.push(s[i]);
} else {
arr01.push(s[i]);
arr02.push(s[i].toUpperCase());
}
}
return [arr01.join(""), arr02.join("")];
}
console.log(capitalize("abcdef")); // ["AbCdEf", "aBcDeF"]
console.log(capitalize("codewars")); // ["CoDeWaRs", "cOdEwArS"]
console.log(capitalize("codewarriors")); // ["CoDeWaRrIoRs", "cOdEwArRiOrS"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment