日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ruby中!!_Ruby反向! 功能

發布時間:2025/3/11 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ruby中!!_Ruby反向! 功能 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ruby中!!

逆轉! Ruby中的功能 (reverse! function in Ruby)

As the name suggests, reverse! function is used to reverse the elements of an array. Most of the times, we need to reverse an array but if we do it with the help of loops, the program will become quite lengthy and time-consuming. Ruby facilitates you with reverse! function which produces the reverse of the array. Unlike, reverse function in Ruby, reverse! produces changes in the original array itself. It also returns the reverse of the array which can be stored in the corresponding new array for the fulfillment of future operations.

顧名思義, 反向! 函數用于反轉數組的元素。 在大多數情況下,我們需要反轉數組,但是如果在循環的幫助下完成該程序,則該程序將變得相當冗長且耗時。 Ruby為您提供反向幫助! 函數產生與數組相反的結果。 與Ruby中的反向功能不同, 反向! 在原始數組本身中產生更改。 它還返回數組的倒序,可以將其存儲在相應的新數組中,以實現將來的操作。

Syntax:

句法:

Array_name.reverse!

Now, let us understand the implementation concept in a much broader way with the help of program codes.

現在,讓我們借助程序代碼以更廣泛的方式理解實現概念。

Example 1:

范例1:

=begin Ruby program to demonstrate implementation of reverse! function =end# Initializing some arrays of elements Arr1 = ["apple", "mango", "banana", "apricot", "plum", "cherry"] Arr2 = ["one","two", "three", "four", "five"] Arr3 = [10,20] Arr4 = [110, 210, 310, 410, 510] Arr5 = ["C++", "Java", "C#", "Visual Basic", "Perl", "Python"] Arr6 = ["Hrithik", "Satyam", "Amisha", "Kajal", "Wamp"] # Invoking reverse! function NewArr1 = Arr1.reverse! NewArr2 = Arr2.reverse! NewArr3 = Arr3.reverse! NewArr4 = Arr4.reverse! NewArr5 = Arr5.reverse! NewArr6 = Arr6.reverse!# Printing the the corresponding arrays puts "#{NewArr1}" puts "#{NewArr2}" puts "#{NewArr3}" puts "#{NewArr4}" puts "#{NewArr5}" puts "#{NewArr6}"

Output

輸出量

["cherry", "plum", "apricot", "banana", "mango", "apple"] ["five", "four", "three", "two", "one"] [20, 10] [510, 410, 310, 210, 110] ["Python", "Perl", "Visual Basic", "C#", "Java", "C++"] ["Wamp", "Kajal", "Amisha", "Satyam", "Hrithik"]

Code logic:

代碼邏輯:

In the above code, we have initialized six arrays. We are reversing them with the help of reverse! statement and storing the returned array in a new corresponding array. Eventually, we are printing the corresponding new arrays.

在上面的代碼中,我們已經初始化了六個數組。 我們正在反轉的幫助下反轉它們! 語句并將返回的數組存儲在新的對應數組中。 最終,我們將打印相應的新數組。

Now, let us see verify whether reverse! function produces changes in the original array or not.

現在,讓我們看看是否可以逆轉! 函數是否在原始數組中產生更改。

Example 2:

范例2:

=begin Ruby program to demonstrate implementation of reverse! function =end# Initializing some arrays of elements Arr1 = ["apple", "mango", "banana", "apricot", "plum", "cherry"] Arr2 = ["one","two", "three", "four", "five"] Arr3 = [10,20] Arr4 = [110, 210, 310, 410, 510] Arr5 = ["C++", "Java", "C#", "Visual Basic", "Perl", "Python"] Arr6 = ["Hrithik", "Satyam", "Amisha", "Kajal", "Wamp"] # Invoking reverse! function NewArr1 = Arr1.reverse! NewArr2 = Arr2.reverse! NewArr3 = Arr3.reverse! NewArr4 = Arr4.reverse! NewArr5 = Arr5.reverse! NewArr6 = Arr6.reverse!# Printing the the corresponding arrays puts "#{Arr1}" puts "#{Arr2}" puts "#{Arr3}" puts "#{Arr4}" puts "#{Arr5}" puts "#{Arr6}"

Output

輸出量

["cherry", "plum", "apricot", "banana", "mango", "apple"] ["five", "four", "three", "two", "one"] [20, 10] [510, 410, 310, 210, 110] ["Python", "Perl", "Visual Basic", "C#", "Java", "C++"] ["Wamp", "Kajal", "Amisha", "Satyam", "Hrithik"]

Code Logic:

代碼邏輯:

In the above code, we have tried to show that reverse! function produces changes in the original array as well with the help of ‘puts’ statement through which we are printing the arrays.

在上面的代碼中,我們試圖證明這種相反! 函數會在原始數組中產生更改,并借助“ puts”語句來打印數組。

翻譯自: https://www.includehelp.com/ruby/reverse-1-function.aspx

ruby中!!

總結

以上是生活随笔為你收集整理的ruby中!!_Ruby反向! 功能的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。