[#94657] [Ruby master Feature#16131] Remove $SAFE, taint and trust — naruse@...
Issue #16131 has been reported by naruse (Yui NARUSE).
3 messages
2019/08/29
[ruby-core:94132] [Ruby master Feature#16039] Array#contains? to check if one array contains another array
From:
eregontp@...
Date:
2019-08-03 12:58:07 UTC
List:
ruby-core #94132
Issue #16039 has been updated by Eregon (Benoit Daloze). cha1tanya (Prathamesh Sonpatki) wrote: > I wanted to avoid creating Set objects just for the purpose of this check so my motivation was to have such method on Array. `Array#-` and any efficient (O(n+m) and not O(n*m), n the size of the LHS, m the size of the RHS) implementation of a superset check needs to use some kind of Hash internally. So you might save a Set allocation, but internally it has to allocate a Hash anyway, so I don't think there is much of a difference, performance-wise. I would recommend defining a helper method like you did above if you use this frequently in your code base. ---------------------------------------- Feature #16039: Array#contains? to check if one array contains another array https://bugs.ruby-lang.org/issues/16039#change-80381 * Author: cha1tanya (Prathamesh Sonpatki) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- 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 ``` -- https://bugs.ruby-lang.org/ Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>