Generalizing JS map-reduce queries