Array include any value from another array?

(cheeses & foods).empty?

As Marc-AndrĂ© Lafortune said in comments, & works in linear time while any? + include? will be quadratic. For larger sets of data, linear time will be faster. For small data sets, any? + include? may be faster as shown by Lee Jarvis’ answer — probably because & allocates a new Array while another solution does not and works as a simple nested loop to return a boolean.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)