Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Array
- def sum
- ans = self.inject{|ac, n| ac += n}
- ans ? ans : 0
- end
- def square
- map{|n| n * n}
- end
- def square!
- ans = []
- for i in 1 .. length - 1
- self[i] = self[i] * self[i]
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement