Strings Problem Set 9

String.25Repeat End

Given a string and an int N, return a string made of N repetitions of the last N characters of the string. You may assume that N is between 0 and the length of the string, inclusive.

  1. repeatEnd("Hello", 3) . "llollollo"
  2. repeatEnd("Hello", 2) . "lolo"
  3. repeatEnd("Hello", 1) . "o"

Solutions:

python

raptor

String.26Repeat Front

Given a string 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, 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()).
  1. repeatFront("Chocolate", 4) . "ChocChoChC"
  2. repeatFront("Chocolate", 3) . "ChoChC"
  3. repeatFront("Ice Cream", 2) . "IcI"

Solutions:

python

raptor

String.27Repeat Separator

Given two strings, word and a separator, return a big string made of count occurences of the word, separated by the separator string.
  1. repeatSeparator("Word", "X", 3) . "WordXWordXWord"
  2. repeatSeparator("This", "And", 2) . "ThisAndThis"
  3. repeatSeparator("This", "And", 1) . "This"

Solutions:

python

raptor