Skip to content

Instantly share code, notes, and snippets.

@forrestblade
Created October 20, 2020 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forrestblade/0cfb907e51cbcd4852f1b0f49670c98f to your computer and use it in GitHub Desktop.
Save forrestblade/0cfb907e51cbcd4852f1b0f49670c98f to your computer and use it in GitHub Desktop.
no carry
const noCarry = (val1, val2) => {
val1 = val1.toString().split('').map(x => parseInt(x))
val2 = val2.toString().split('').map(x => parseInt(x))
const f = (arr1, arr2) => {
const a = arr1.length > arr2.length ? arr1 : arr2;
const b = arr1.length > arr2.length ? arr2 : arr1;
let result = []
a.reverse().forEach((e, i) => {
const aux = b.length - 1;
result[i] = e + (b[aux - i] ? b[aux - i] : 0);
})
return result.reverse()
}
const solution = f(val1, val2).map(x => x.toString()).reduce((sum, val) => sum + +val)
return solution
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment