Created
March 20, 2013 02:46
-
-
Save kayline/5201913 to your computer and use it in GitHub Desktop.
DBC Prework - Pad an array. In the second method, removing "clone" from line 17 causes the code to fail the 4th spec test, for padding the array with "apples". Why? It seems like all that should do is cause it to fail the 3rd spec test, for a non-destructive method.
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
class Array | |
def pad!(min_size, value = nil) | |
array = self | |
diff = min_size - self.length | |
if diff <= 0 | |
return self | |
else | |
diff.times do | |
array.push(value) | |
end | |
return array | |
end | |
end | |
def pad(min_size, value = nil) | |
array = self.clone | |
array.pad!(min_size, value) | |
return array | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment