Skip to content

Latest commit

 

History

History
27 lines (23 loc) · 309 Bytes

8 kyu - Opposite number.md

File metadata and controls

27 lines (23 loc) · 309 Bytes

Task

Very simple, given a number, find its opposite.

Examples:

1: -1 14: -14 -34: 34 But can you do it in 1 line of code and without any conditionals?

My solution

def opposite(n)
  if n
    return n*-1
  else
   return false
  end
end

Better solution

def opposite n
  -n
end