I was looking over the Quiz Summary in Solitaire Cipher, when I stumbled upon this block of code:
def triple_cut
a = @deck.index( 'A' )
b = @deck.index( 'B' )
a, b = b, a if a > b
@deck.replace( [ @deck[(b + 1)..-1],
@deck[a..b],
@deck[0...a] ].flatten )
end
I don't understand why there's a separate method replace
for this. Why not just do the following?
@deck = @deck[(b + 1)..-1] +
@deck[a..b] +
@deck[0...a]
Why go through the trouble of applying two separate methods (replace
and flatten
) when you could just add them together? I didn't run into any problems with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With