Use of map and reduce functions in Javascript