I'm new to ruby and I'm wondering why this error comes up. (Sorry for bad formatting)
Error:
rb37: in '%': nil can't be coerced into Fixnum (TypeError)
And also I need help with my question. I'm suppose to come up with a method to run through a list of 1 million ID numbers to find a specific ID using the most efficient way possible (in less than 5min). I've been at this the whole afternoon :(
def exist?(id)
dump = []
employee_list = $employee_list.sort #employee_list is an array of 1 million lines of data, I have to look for a specific "id"
while dump.length < id
dump << employee_list.first
if dump.last != id
if id%dump.last != 0 && dump.last != 1
employee_list.delete_if { |n| n%dump.last == 0 }
#what im doing here is to delete ID from employee_list that are multiples of n
elsif id%dump.last == 0
employee_list.delete_if { |m| m%dump.last == 0 && m!=id }
#deleting multiples of m (excluding id itself)
end
elsif dump.last == id
return true
end
end
return false
end