Created
August 4, 2017 13:23
-
-
Save PantherHawk/ee0ac717e8bfd965fdf6ede5b03a3eb4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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