Created
April 22, 2010 10:16
-
-
Save Sedward/375057 to your computer and use it in GitHub Desktop.
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
function city_map() { | |
emit({state:this.state, city:this.city}, {zips:1, pop:this.pop}); | |
} | |
function city_reduce(key, values) { | |
out = {zips:0, pop:0}; | |
values.forEach(function (val) { | |
out.zips += val.zips; | |
out.pop += val.pop; | |
}); | |
return out; | |
} | |
function city_finalize(key, val) { | |
val.people_per_zip = val.pop / val.zips; | |
return val; | |
} | |
function state_map() { | |
emit(this._id.state, {zips:this.value.zips, pop:this.value.pop, cities:1}); | |
} | |
function state_reduce(key, values) { | |
out = {zips:0, pop:0, cities:0}; | |
values.forEach(function (val) { | |
out.zips += val.zips; | |
out.pop += val.pop; | |
out.cities += val.cities; | |
}); | |
return out; | |
} | |
function state_finalize(key, val) { | |
val.people_per_zip = val.pop / val.zips; | |
val.people_per_city = val.pop / val.cities; | |
val.zips_per_city = val.zips / val.cities; | |
return val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment