I am looking at the Mumbling code challenge on CodeWars:
The examples below show you how to write function
accum:Examples:
accum("abcd") -> "A-Bb-Ccc-Dddd" accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy" accum("cwAt") -> "C-Ww-Aaa-Tttt"The parameter of
accumis a string which includes only letters froma..zandA..Z.
This is my attempt:
function accum(s) {
const holdArr = [...s];
const tempArr = [];
for (let i = 0; i < holdArr.length; i++) {
tempArr.push(holdArr[i].repeat(i + 1).toLowerCase());
}
return tempArr.join("-").replace(/(^|-\w)/g, (x) => x.toUpperCase());
}
The problem is that within input like:
console.log(accum("abCd"));
...it gives output: a-Bb-Ccc-Ddd, but it should give A-Bb-Ccc-Dddd. How can I tune the RegEx to get it?