Description:
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
.
自己解法:
function write(string){ return string.split('').map(function(item,index){ return item.toUpperCase()+ new Array( index +1).join(item.toLowerCase()); }).join('-') } write('ZpglnRxqenU');
这几天一直都是操作字符串数组 ,没啥说的
别人解题:
1
这个就是新标准里的 =>用法
2
3