X106: repeatFront

Given a string str and an int n, return a string made of the first n characters of the string, followed by the first n - 1 characters of the string, then the first n - 2, and so on. You may assume that n is between 0 and the length of the string, inclusive (i.e. n >= 0 and n <= str.length()).

Examples:

repeatFront("Chocolate", 4) -> "ChocChoChC"
repeatFront("Chocolate", 3) -> "ChoChC"

Your Answer:

Feedback

Your feedback will appear here when you check your answer.