est-il une autre façon simple,nicer
?comparer deux réseaux à l'exception de l'élément x, y, z (rubis)
require 'pp'
a1 = ["02/28/10","Webinars","131","0","26 Feb 2010","0","3d, 8h, 49m, 18s"]
a2 = ["02/20/10","Webinars","131","9","26 Feb 2010","0","3d, 8h, 49m, 18s"]
def compare(array1,array2,ignore)
tmp1 = Array.new
tmp2 = Array.new
0.upto(array1.length-1) {|index|
if !ignore.include?(index)
tmp1 << array1[index]
tmp2 << array2[index]
end
}
if tmp1 == tmp2
return true
else
return false
end
end
pp a1
pp a2
puts
puts compare(a1,a2,[0,3])
et la sortie est
["02/28/10", "Webinars", "131", "0", "26 Feb 2010", "0", "3d, 8h, 49m, 18s"]
["02/20/10", "Webinars", "131", "9", "26 Feb 2010", "0", "3d, 8h, 49m, 18s"]
true
pour votre information, la version en question revient toujours vrai, parce que tmp1 et le point de tmp2 au même tableau. Essayez de comparer ([0], [1], []) –
merci de le signaler. Fixé. – Radek