Next level string padding
Description:
In the wake of the npm's left-pad
debacle, you decide to write a new super padding method that superceds the functionality of left-pad
. Your version will provide the same functionality, but will additionally add right, and justified padding of string -- the super_pad
.
Your function super_pad
should take three arguments: the string string
, the width of the final string width
, and a fill character fill
. However, the fill character can be enriched with a format string resulting in different padding strategies. If fill
begins with '<'
the string is padded on the left with the remaining fill string and if fill
begins with '>'
the string is padded on the right. Finally, if fill
begins with '^'
the string is padded on the left and the right, where the left padding is always greater or equal to the right padding. The fill
string can contain more than a single char, of course.
Some examples to clarify the inner workings:
super_pad("test", 10)
returns" test"
super_pad("test", 10, "x")
returns"xxxxxxtest"
super_pad("test", 10, "xO")
returns"xOxOxOtest"
super_pad("test", 10, "xO-")
returns"xO-xO-test"
super_pad("some other test", 10, "nope")
returns"other test"
super_pad("some other test", 10, "> ")
returns"some other"
super_pad("test", 7, ">nope")
returns"testnop"
super_pad("test", 7, "^more complex")
returns"motestm"
super_pad("test", 7, "")
returns"test"
The super_pad
method always returns a string of length width
if possible. We expect the width
to be positive (including 0) and the fill could be also an empty string.
Similar Kata:
Stats:
Created | Mar 24, 2016 |
Published | Mar 25, 2016 |
Warriors Trained | 367 |
Total Skips | 33 |
Total Code Submissions | 1641 |
Total Times Completed | 97 |
Python Completions | 78 |
Ruby Completions | 22 |
Total Stars | 13 |
% of votes with a positive feedback rating | 73% of 45 |
Total "Very Satisfied" Votes | 27 |
Total "Somewhat Satisfied" Votes | 12 |
Total "Not Satisfied" Votes | 6 |
Total Rank Assessments | 11 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |