Skip to content

Instantly share code, notes, and snippets.

@PantherHawk
Created August 4, 2017 13:23
Show Gist options
  • Save PantherHawk/ee0ac717e8bfd965fdf6ede5b03a3eb4 to your computer and use it in GitHub Desktop.
Save PantherHawk/ee0ac717e8bfd965fdf6ede5b03a3eb4 to your computer and use it in GitHub Desktop.
decimalZip = (A, B) => {
if ( typeof A !== "number" || typeof B !== "number" ) {
return undefined;
}
var a = JSON.stringify(A).split('')
var b = JSON.stringify(B).split('')
var c = [];
var longer = a.length > b.length ? a : b;
for (var i = 0; i < longer.length; i++) {
if (a.length) {
c.push(a.shift())
} else {
c.push(b.splice(b[i]))
}
if (b.length) {
c.push(b.shift())
} else {
c.push(a.splice(a[i]))
}
}
if (a.length !== b.length) {
var rest = a.length > b.length ? a : b;
c.push(rest.join(''))
}
return parseInt(c.join(''));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment