Skip to content

Instantly share code, notes, and snippets.

@utumno86
Last active August 29, 2015 14:24
Show Gist options
  • Save utumno86/1d1edf0795bcc7d628ac to your computer and use it in GitHub Desktop.
Save utumno86/1d1edf0795bcc7d628ac to your computer and use it in GitHub Desktop.
ArrayReversal
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