solution for Array exercise 6