Project

General

Profile

Actions

Feature #16039

open

Array#contains? to check if one array contains another array

Added by cha1tanya (Prathamesh Sonpatki) over 4 years ago. Updated over 4 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:94115]

Description

I woud like to propose Array#contains? which will check if the one array is part of another array.
Implementation can be as follows:

def contains?(other)
  (other - self).empty?
end

Some test cases:

[1, 2, 3].contains?([2, 3]) => true
[1, 2, 3].contains?([]) => true
[1, 2, 3].contains?([1, 2, 3, 4]) => false
[].contains?([]) => true
[].contains?([1, 2, 3, 4]) => false
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0