Doing exercise 1 with foldLeft
exercise 2