mapReduce complexity

mapReduce invokes both 'map' and 'reduce', for a complexity of O(2n)
This commit changes mapReduce to avoid calling map and reduce, making it O(n).