Problem 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.
Level:7kyu
Link to kata: Mumbling
For the above Kata we first split the given string into an array of characters by Javascript .split() function. Then we declare a variable "ans" initialized to an empty string. We loop through every character of an array starting with index 0. We add a string of character of array in uppercase form and then we add the lowercase form of same character the same number of times the index. After this we check if the index has reached the end of the array or not. If it has not then we add a '-' to the "ans" string otherwise we just come out of the loop.
In the end we return the "ans" variable as our output for the function.
Here is a link to the code: Kata Day 24
Please mention your suggestions or your doubts in the comment below.
Happy coding. :)
No comments:
Post a Comment