move to JavaScript map reduce