Created
August 28, 2012 00:42
-
-
Save philips/3493889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This function replaces any portion of a string and returns an identically | |
# sized string. How might the sanity tests at the top fail to return an | |
# identical sized string. | |
# | |
# Where else is it broken? | |
# | |
# How would you test it? | |
def slice_and_transform(str, loc, len, rep) | |
if (loc < 1) | |
return nil | |
end | |
if (loc + len > str.length) | |
return nil | |
end | |
str.slice!(loc, len) | |
return str + rep | |
end | |
str = "Hello Earth" | |
loc = 6 | |
rep = "Venus" | |
puts(slice_and_transform(str, loc, rep.length, rep)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment