use Array.map instead of for loop