我有一个值数组
=> [0.0, 4.76, 0.0, Infinity, NaN, 2.63, 0.74, 10.0, NaN, NaN, NaN, NaN, 0.0, NaN, NaN, NaN, NaN, NaN, Infinity, 5.26, NaN, 0.0, NaN, 3.45, 2.5, NaN, 10.0, 0.0, NaN, 2.94, NaN, NaN, 0.0, 2.04, 0.0, 11.11, NaN, NaN, 1.23, NaN, NaN, 11.11, NaN, NaN, NaN, 0.0, 9.68, NaN, NaN, 10.0, 5.0, 3.7, 10.0, Infinity, 0.0, 0.0, 1.41, NaN, 3.45, NaN]
当我运行此脚本删除NaN时,它会删除部分但不是全部的NaN。
def remove_from_array(numArray)
numArray.inject(0) do |i|
if numArray[i].nan?
numArray.delete_at(i)
end
i += 1
end
numArray
end
我错过了什么?
答案 0 :(得分:6)