Skip to content

Instantly share code, notes, and snippets.

@jkomyno
Created August 31, 2016 12:20
Show Gist options
  • Save jkomyno/be38df107b24d45922f67aa17c4df3c4 to your computer and use it in GitHub Desktop.
Save jkomyno/be38df107b24d45922f67aa17c4df3c4 to your computer and use it in GitHub Desktop.
Utility to sort three correlated array by merging them temporarily into objects. This utility sorts according to srttList (the third array).
function threeArraySort(ipList, macList, srttList) {
var list = [];
for (var j in ipList)
list.push({'ip': ipList[j], 'mac': macList[j], 'srtt': srttList[j] });
list.sort(function(a, b) {
return ((a.srtt < b.srtt) ? -1 : ((a.srtt == b.srtt) ? 0 : 1));
});
for (var k = 0; k < list.length; k++) {
ipList[k] = list[k].ip;
macList[k] = list[k].mac;
srttList[k] = list[k].srtt;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment