solved exercise 6 from arrays