How to sort an array
Use the Array "sort" method.
fruit = ["oranges", "apples", "bananas"] sorted = fruit.sortArrays are sorted by comparing each element of the array using the <=> comparison operator. When comparing two arrays themselves "<=>" checks and compares each element of the arrays. So for example:# => ["apples", "bananas", "oranges"]fruit# => ["oranges", "apples", "bananas"]fruit.sort! fruit# => ["apples", "bananas", "oranges"]
array1 = ["a",7] array2 = ["a",6] array1 <=> array2So if you sort this array:# => would return +1 meaning array1 is greater than array2
fruit = [ ["avacados", 1], ["apples", 2], ["carrots", 3] ]# => you'll getfruit.sort# => [ ["apples", 2], ["avacados", 1], ["carrots", 3] ]