Scala: a version of the first challenge that works directly with arrays