Skip to content

Instantly share code, notes, and snippets.

@nmalkin
Created November 27, 2013 02:43
Show Gist options
  • Save nmalkin/7669893 to your computer and use it in GitHub Desktop.
Save nmalkin/7669893 to your computer and use it in GitHub Desktop.
Coordinate sorting example
var zip = function(array1, array2) {
return array1.map(function(v, i) {
return {x: v,
y: array2[i]};
});
};
var xs = [8,7,6,5];
var ys = [4,3,2,1];
var coordinates = zip(xs, ys);
console.log(coordinates);
var compareCoordinates = function(c1, c2) {
return c1.x - c2.x;
};
var sortedCoordinates = coordinates.sort(compareCoordinates);
console.log(sortedCoordinates);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment