Created
November 27, 2013 02:43
-
-
Save nmalkin/7669893 to your computer and use it in GitHub Desktop.
Coordinate sorting example
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
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