arr[-1,-1]_Rubyで-演算子(new_array->arr-old_array)を使用して配列インスタンスを作成する

4596 ワード

arr[-1,-1]
In the last article, we have gone through the method by which we can create Array instance with the help of + operator. You all must know that in the articles which were related to Array creation are Public class methods and now in most of the previous articles, we have learned about Public instance methods. For a quick overview, we have studied & operator, * operator, etc. We also know that what is the difference between Public Instance methods and Public class methods. We have studied methods like Array.new() which is a resident of Public class methods but now will be studying Public instance methods. Well, in this article, we will be studying about creating the Array instance with the help of the - operator.
前回の記事では、+演算子の助けでArrayインスタンスを作成できる方法について説明しました.Arrayの作成に関連する記事では、Publicクラスメソッドであることを知っておく必要があります.現在、前の多くの記事では、Publicインスタンスメソッドについて理解しています.すばやく閲覧するために,&演算子,*演算子などを検討した.Public InstanceメソッドとPublicクラスメソッドの違いも知っています.私たちはArrayを研究しました.New()のような方法は,Public系の方法の住民であるが,現在Publicの実例法を検討する.では、本稿では、-演算子の助けでArrayインスタンスを作成する方法について検討します.
Method description:
メソッドの説明:
This is one of the ways through which you can generate new Array. It works in the way that it returns the copy of the original Array that is the copy of the first Array and this copy does not contain the elements which are present in the second Array. The order which is followed in the new Array is dependent upon the Original Array. This method uses .eql method for efficient processing.
これは新しい配列を生成する方法の1つです.元の配列のコピー(すなわち、最初の配列のコピー)を返し、2番目の配列に存在する要素を含まないようにします.新しいアレイで従う順序は、元のアレイによって異なります.このメソッドを使用します.eqlメソッドは有効な処理を行う.
Parameter(s):
パラメータ:
The '-' operator takes two arguments. The first one is the previously defined Array and the second one is another Array.
「-」演算子には2つのパラメータが使用されます.1つ目は前に定義された配列で、2つ目は別の配列です.
Example 1:
例1:=begin   Ruby program to create Array with - operator =end # arrays old_arr1 = [23,44,66,889] old_arr2 = [33,56,22,23] # creating a new array new_arr = old_arr1 - old_arr2 # printing the array puts "The new Integer Array Instance is: " print new_arr Output
しゅつりょくりょうThe new Integer Array Instance is: [44, 66, 889] Explanation:
説明:
In the above code, you can observe that we are creating an Array instance with the help of the - operator. In the resulting Array, you can see that the new Array is not containing elements that are present in the second Array.
上記のコードでは、-演算子を使用してArrayインスタンスを作成していることがわかります.生成された配列には、新しい配列に2番目の配列に存在する要素が含まれていないことがわかります.
Example 2:
例2:=begin   Ruby program to create Array with - operator =end # arrays old_arr1 = ['Ramit','Amit','Suresh','Payal'] old_arr2 = ['Payal','Samir','Sonakshi','Hira','Panna'] # creating a new array new_arr = old_arr1 - old_arr2 # printing the array puts "The new String Array Instance is: " print new_arr Output
しゅつりょくりょうThe new String Array Instance is: ["Ramit", "Amit", "Suresh"] Explanation:
説明:
In the above code, you can observe that we are creating a String Array with the help of the - operator. The resulting Array is having all the Strings which are present in the first Array but not in the second Array.
上のコードでは、-演算子を使用して文字列配列を作成していることがわかります.結果配列には、最初の配列に表示されるが、2番目の配列には存在しないすべての文字列があります.
翻訳:https://www.includehelp.com/ruby/creating-array-instance-with-minus-operator-new_array-arr-old_array.aspx

arr[-1,-1]