Advertisement
Guest User

Untitled

a guest
Oct 28th, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.22 KB | None | 0 0
  1. class Array
  2.     def sum
  3.         ans = self.inject{|ac, n| ac += n}
  4.         ans ? ans : 0
  5.     end
  6.  
  7.     def square
  8.         map{|n| n * n}
  9.     end
  10.  
  11.     def square!
  12.         ans = []
  13.         for i in 1 .. length - 1
  14.             self[i] = self[i] * self[i]
  15.         end
  16.     end
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement