Created
September 23, 2019 11:42
-
-
Save sryze/749b4857cb15092c0c71798a9527d5df 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
function mergeArraysKeepOrder(a1, a2) { | |
var a = []; | |
var i = 0, j = 0; | |
while (true) { | |
for (; i < a1.length; i++) { | |
if (a2.indexOf(a1[i], j) != -1) { | |
i++; | |
break; | |
} | |
a.push(a1[i]); | |
} | |
for (; j < a2.length; j++) { | |
if (a1.indexOf(a2[j], i) != -1) { | |
j++; | |
break; | |
} | |
a.push(a2[j]); | |
} | |
if (i == a1.length && j == a2.length) { | |
break; | |
} | |
} | |
return a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment