博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
arr[-1,-1]_在Ruby中使用-运算符(new_array-> arr-old_array)创建数组实例
阅读量:2529 次
发布时间:2019-05-11

本文共 2900 字,大约阅读时间需要 9 分钟。

arr[-1,-1]

In the last article, we have gone through the method by which we can . 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 , , etc. We also know that what is the difference between Public Instance methods and Public class methods. We have studied methods like 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创建相关的文章中,都是Public类方法,现在在前面的大多数文章中,我们已经了解了Public实例方法。 为了快速浏览,我们研究了 , 等。我们还知道Public Instance方法和Public类方法之间的区别是什么。 我们研究了之类的方法,该方法是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.

这是生成新数组的方式之一。 它的工作方式是返回原始数组的副本(即第一个数组的副本),并且此副本不包含第二个数组中存在的元素。 新阵列中遵循的顺序取决于原始阵列。 此方法使用.eql方法进行有效处理。

Parameter(s):

参数:

The '-' operator takes two arguments. The first one is the previously defined Array and the second one is another Array.

“-”运算符采用两个参数。 第一个是先前定义的数组,第二个是另一个数组。

Example 1:

范例1:

=begin  Ruby program to create Array with - operator=end# arraysold_arr1 = [23,44,66,889]old_arr2 = [33,56,22,23]# creating a new array new_arr = old_arr1 - old_arr2# printing the arrayputs "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实例 。 在生成的数组中,您可以看到新数组不包含第二个数组中存在的元素。

Example 2:

范例2:

=begin  Ruby program to create Array with - operator=end# arraysold_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.

在上面的代码中,您可以观察到我们正在使用-运算符创建一个字符串数组 。 结果数组具有所有出现在第一个数组中但不存在于第二个数组中的字符串。

翻译自:

arr[-1,-1]

转载地址:http://okxzd.baihongyu.com/

你可能感兴趣的文章
RocketMQ配置
查看>>
vs code调试console程序报错--preLaunchTask“build”
查看>>
蚂蚁金服井贤栋:用技术联手金融机构,形成服务小微的生态合力
查看>>
手机通话记录统计分析
查看>>
富文本编辑器比较
查看>>
端口号大全
查看>>
机器学习基石笔记2——在何时可以使用机器学习(2)
查看>>
POJ 3740 Easy Finding (DLX模板)
查看>>
MySQL 处理重复数据
查看>>
关于typedef的用法总结(转)
查看>>
hibernate could not resolve property
查看>>
【strtok()】——分割字符串
查看>>
Linux下安装rabbitmq
查看>>
曹德旺
查看>>
【转】判断点在多边形内(matlab)
查看>>
java基础之集合:List Set Map的概述以及使用场景
查看>>
Python 线程 进程 协程
查看>>
骨牌覆盖问题
查看>>
iOS语言中的KVO机制
查看>>
excel第一次打开报错 向程序发送命令时出错 多种解决办法含终极解决方法
查看>>