replace for loop with map
replace each with reduce
jslint