7 kyu · reference

Mumbling

FundamentalsStringsPuzzles

This time no story, no theory. 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 accum is a string which includes only letters from a..z and A..Z.

Solutions

01-solution.jsView on GitHub ↗
function accum(s) {
	return s
		.toLowerCase()
		.split('')
		.reduce((acc, char, idx) => {
			acc.push(`${char.toUpperCase()}${char.toLowerCase().repeat(idx)}`);
			return acc;
		}, [])
		.join('-');
}