Write a Ruby program to check whether all items are identical in a given array.
num1 = [10, 20, 30, 40, 10, 10, 20] print "Original array:\n" print num1 print "\nIs all items are identical?\n" print num1.all? {|x| x == num1[0]} num2 = [10, 10, 10] print "\nOriginal array:\n" print num2 print "\nIs all items are identical?\n" print num2.all? {|x| x == num2[0]}
Output:
Original array: [10, 20, 30, 40, 10, 10, 20] Is all items are identical? false Original array: [10, 10, 10] Is all items are identical? true
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer