Created
February 13, 2013 15:29
-
-
Save cmourouvin/4945396 to your computer and use it in GitHub Desktop.
Un map, il ne manque plus que le reduce
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
map_closest | |
function map_closest() { | |
var pitt = [-80.064879, 40.612044]; | |
var phil = [-74.978052, 40.089738]; | |
function distance(a, b) { | |
var dx = a[0] - b[0]; | |
var dy = a[1] - b[1]; | |
return Math.sqrt(dx * dx + dy * dy); | |
} | |
if (distance(this.loc, pitt) < distance(this.loc, phil)) { | |
emit("pitt", 1); | |
} else { | |
emit("phil", 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment