stringAddition method

String stringAddition(
  1. String s1,
  2. String s2
)

Implementation

String stringAddition(String s1, String s2) {
  assert(s1.length == s2.length);
  final List<String> result = List<String>.filled(s2.length, '0');
  int c = 0;
  for (int i = s1.length - 1; i >= 0; i--) {
    final int t = c + dig(s1[i]) + dig(s2[i]);
    result[i] = cdig(t % 10);
    c = t ~/ 10;
  }
  assert(c == 0);
  return result.join();
}