It all depends on what you want to do with the data later. It may make sense for you to put in average values but if you have relatively small arrays and are down for a little fun you can go all Bayesian with something like the following:
require 'classifier'
$c = Classifier::Bayes.new
perm = [1, 2, 3, 4, 5].permutation(5)
perm.each { |v| $c.add_category v * "," }
perm.each { |v| $c.train v*"," , v*"," }
def guess(arr)
s = $c.classify(arr*",")
a = s.split(',').map{|s| s.to_i}
end
tests = [
[1,2,3,4,5],
[1,2,3,nil,5],
[nil,2,3,4,5],
[1,nil,nil,4,5],
[1,nil,nil,nil,5],
[nil,nil,3,nil,nil],
[nil,nil,nil,nil,nil]
]
tests.each { |t| puts "Array #{t.inspect} became #{guess(t).inspect}" }
Output looks like the following:
Array [1, 2, 3, 4, 5] became [1, 2, 3, 4, 5]
Array [1, 2, 3, nil, 5] became [1, 2, 3, 4, 5]
Array [nil, 2, 3, 4, 5] became [1, 2, 3, 4, 5]
Array [1, nil, nil, 4, 5] became [1, 2, 3, 4, 5]
Array [1, nil, nil, nil, 5] became [1, 2, 3, 4, 5]
Array [nil, nil, 3, nil, nil] became [1, 2, 3, 4, 5]
Array [nil, nil, nil, nil, nil] became [1, 2, 3, 4, 5]