Guest User

Untitled

a guest
Jan 12th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.53 KB | None | 0 0
  1. def string_reverse(str)
  2.   len = str.length - 1
  3.   n = 0
  4.   while n < len do
  5.     # Particularly proud of this since it's essentially language agnostic.
  6.     str[n] ^= str[len]
  7.     str[len] ^= str[n]
  8.     str[n] ^= str[len]
  9.     p str
  10.     p n
  11.     p len
  12.     n += 1
  13.     len -= 1
  14.   end
  15.   return str
  16. end
  17.  
  18. describe StringRev do
  19.   describe "when a String is passed to the reverse method" do
  20.     it "should return the reverse of that string" do
  21.       string_reverse("Christopher Allen").must_equal "nellA rehpotsirhC"
  22.     end
  23.   end
  24. end
Add Comment
Please, Sign In to add comment