OneBite.Dev - Coding blog in a bite size

check if two arrays are equal in Ruby

Code snippet on how to check if two arrays are equal in Ruby

array1 = [1, 2, 3, 4]
array2 = [1, 2, 3, 4]

if array1 == array2
  puts "Arrays are equal!"
end

This code is comparing two arrays, array1 and array2. It is using the double equal operator to check if the two arrays are equal. This operator checks for equality between the two arrays, meaning that array1 and array2 have the same elements and are in the same order. If the comparison is true, meaning the arrays are equal, it will print out a message ‘Arrays are equal!’

ruby