use anonymous function in loop to avoid code repetition (DRY) and suppress temporary  variable