Ruby 数组sort!()函数

Ruby 数组sort!()函数

Array#sort!() : sort!() 是一个数组类的方法,它返回排序到位的自家数组。

语法。Array.sort!()

参数。数组

返回:已排序的自我数组的位置。

例子 #1 :

# Ruby code for sort!() method
  
# declaring array
a = ["abc", "nil", "dog"]
  
# declaring array
c = ["cat", "efg", "geeks"]
  
# declaring array
b = ["cow", "coal", "dog"]
  
arr = [a, b, c]
  
# sort! method example
puts "sort!() method form : #{arr.sort!()}\n\n"

输出:

sort!() method form : [["abc", "nil", "dog"], ["cat", "efg", "geeks"], ["cow", "coal", "dog"]]

例子 #2 :

# Ruby code for sort!() method
  
# declaring array
a = ["abc", "nil", "dog"]
  
# declaring array
c = ["cat", "efg", "geeks"]
  
# declaring array
b = ["cow", "coal", "dog"]
  
  
# sort! method example
puts "sort!() method form : #{a.sort!()}\n\n"
  
puts "sort!() method form : #{b.sort!()}\n\n"
  
puts "sort!() method form : #{c.sort!()}\n\n"

输出:

sort!() method form : ["abc", "dog", "nil"]

sort!() method form : ["coal", "cow", "dog"]

sort!() method form : ["cat", "efg", "geeks"]

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程