Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
bdacdfae
Commit
bdacdfae
authored
5 years ago
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `Array#intersection` which is new in Ruby2.7.
parent
682406a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
mrbgems/mruby-array-ext/mrblib/array.rb
mrbgems/mruby-array-ext/mrblib/array.rb
+18
-0
mrbgems/mruby-array-ext/test/array.rb
mrbgems/mruby-array-ext/test/array.rb
+8
-0
No files found.
mrbgems/mruby-array-ext/mrblib/array.rb
View file @
bdacdfae
...
...
@@ -173,6 +173,24 @@ class Array
array
end
##
# call-seq:
# ary.intersection(other_ary,...) -> new_ary
#
# Set Intersection---Returns a new array containing elements common to
# this array and <i>other_ary</i>, removing duplicates.
#
# ["a", "b", "c"].union(["c", "d", "a"], ["a", "c", "e"])
# #=> ["a", "b", "c", "d", "e"]
#
def
intersection
(
*
args
)
ary
=
self
args
.
each
do
|
x
|
ary
=
ary
&
x
end
ary
end
##
# call-seq:
# ary.flatten -> new_ary
...
...
This diff is collapsed.
Click to expand it.
mrbgems/mruby-array-ext/test/array.rb
View file @
bdacdfae
...
...
@@ -111,6 +111,14 @@ assert("Array#&") do
assert_equal
[
1
,
2
,
3
,
1
],
a
end
assert
(
"Array#intersection"
)
do
a
=
[
1
,
2
,
3
,
1
,
8
,
6
,
7
,
8
]
b
=
[
1
,
4
,
6
,
8
]
c
=
[
1
,
5
,
7
,
8
]
assert_equal
[
1
,
8
],
a
.
intersection
(
b
,
c
)
end
assert
(
"Array#flatten"
)
do
assert_equal
[
1
,
2
,
"3"
,
{
4
=>
5
},
:'6'
],
[
1
,
2
,
"3"
,
{
4
=>
5
},
:'6'
].
flatten
assert_equal
[
1
,
2
,
3
,
4
,
5
,
6
],
[
1
,
2
,
[
3
,
4
,
5
],
6
].
flatten
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment