Last active
August 29, 2015 14:24
-
-
Save utumno86/1d1edf0795bcc7d628ac to your computer and use it in GitHub Desktop.
ArrayReversal
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
require 'minitest/autorun' | |
describe Array do | |
before do | |
@ary = %w(a b c d e) | |
@temp = "" | |
end | |
it 'it can be reversed in place' do | |
# YOUR SOLUTION HERE | |
n = @ary.length/2 | |
n.times do |i| | |
@temp = @ary[-(i+1)] | |
@ary[-(i+1)] = @ary[i] | |
@ary[i] = @temp | |
end | |
@ary.must_equal %w(e d c b a) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment