added length, sum, and product implemented using foldLeft