Add Two String Numbers

Published by Matt in

Write a function that adds two numbers. The catch, however, is that the numbers will be strings.

Examples

add_str_nums("4", "5") ➞ "9"

add_str_nums("abcdefg", "3") ➞ "-1"

add_str_nums("1", "") ➞ "1"

add_str_nums("1874682736267235927359283579235789257", "32652983572985729") ➞ "1874682736267235927391936562808774986"

Notes

  • If there are any non-numerical characters, return "-1".
  • An empty parameter should be treated as "0".
  • Your function should be able to add any size number.
  • Your function doesn't have to add negative numbers.
  • Zeros at the beginning of the string should be trimmed.
Watch a quick demo on how Edabit works.