Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def string_reverse(str)
- len = str.length - 1
- n = 0
- while n < len do
- # Particularly proud of this since it's essentially language agnostic.
- str[n] ^= str[len]
- str[len] ^= str[n]
- str[n] ^= str[len]
- p str
- p n
- p len
- n += 1
- len -= 1
- end
- return str
- end
- describe StringRev do
- describe "when a String is passed to the reverse method" do
- it "should return the reverse of that string" do
- string_reverse("Christopher Allen").must_equal "nellA rehpotsirhC"
- end
- end
- end
Add Comment
Please, Sign In to add comment