Created
November 4, 2015 21:10
-
-
Save msmorgan/57a824d7b3453f1de9bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
arrays = arrays.map(sort); // sort each sub-array | |
arrays = arrays.sort(function (ary) { return ary.length; }); // sort arrays by length, shortest will be first | |
var indexes = []; | |
for (i = 0; i < arrays.length; i++) { | |
indexes[i] = 0; | |
} | |
var result = []; | |
while (indexes[0] < arrays[0].length) { | |
var allEqual = true; | |
for (i = 1; i < arrays.length; i++) { | |
while (arrays[i][indexes[i]] < arrays[0][indexes[0]]) { | |
indexes[i]++; | |
} | |
if (arrays[i][indexes[i]] != arrays[0][indexes[0]]) { | |
allEqual = false; | |
break; | |
} | |
} | |
if (allEqual) { | |
result.push(arrays[0][indexes[0]]); | |
} | |
indexes[0]++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment