I'm not getting this to work correctly.
I have an array of hashes with a nested arrays of hashes of varying depth. If any of the nested results are false it must return false otherwise true.
array = [
{
result: true,
dependents: [
{
result: true,
dependents: [
{result: true},
{result: false}
]
}
]
},
result: true,
dependents: []
]
def result(array)
if array.find {|line| line[:result] == false}
return false
else
array.each do |line|
result(line[:dependents])
end
end
true
end
result(array)
#=> true (should be false)
The method result() is not working correctly at the moment as it is returning true for the given array and should be false. Any ideas?