Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 586 Bytes

sum_the_strings.md

File metadata and controls

23 lines (18 loc) · 586 Bytes

Description

Create a function that takes 2 integers in form of a string as an input, and outputs the sum (also as a string):

Example: (Input1, Input2 -->Output)

"4", "5" --> "9"
"34", "5" --> "39"
"", "" --> "0"
"2", "" --> "2"
"-5", "3" --> "-2"

Notes:

  • If either input is an empty string, consider it as zero.
  • Inputs and the expected output will never exceed the signed 32-bit integer limit (2^31 - 1)

My Solution

def sum_str(a, b)
  (a.to_i + b.to_i).to_s
end