Ruby rocks: averaging an array of numbers to return a set number
I had a miniature programming challenge earlier today, creating an algorithm to manipulate an array of integers in Ruby. The array can be any length, but it needed to be modified to contain a maximum of, say, 5 elements. So, if the array length is less than 5 just return it, otherwise do something so reduce it to exactly 5 elements. Also, the order had to be maintained (apart from elements that have been removed).