For Loop Inside Function Javascript Code Format