Skip to content

Instantly share code, notes, and snippets.

@cmourouvin
Created February 13, 2013 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmourouvin/4945396 to your computer and use it in GitHub Desktop.
Save cmourouvin/4945396 to your computer and use it in GitHub Desktop.
Un map, il ne manque plus que le reduce
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