[ad_1]
problem: Create a Proc p that will check whether a given array of elements are nil or not. Use .nil? to evaluate elements. Print ‘true’ if elements are nil, and ‘false’ if the elements has a value
Issue: I came up with below solution but its giving me only one value as true instead of checking for each value of array , please help in correcting below code:
Code:
def check_nill(array1)
p = Proc.new{ |num| num.nil?}
c = array1.any?(&p)
return c
end
array1 = [2,nil,8]
result = check_nill(array1)
puts “#{ result1 }”
Output: true
[ad_2]