loading...

re: Daily Challenge #50 - Number Neighbor VIEW POST

FULL DISCUSSION
 

Simple ruby solution(with edge cases):

def neighbors str
  num = str.to_i
  res = case num
  when 0
    [num + 1]
  when 9999999999
    [num - 1]
  when -Float::INFINITY..0, 9999999999..Float::INFINITY
    raise 'Not a phone number'
  else
    [num - 1, num + 1]
  end

  res.map(&:to_s)
end
code of conduct - report abuse