Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > The Easiest way to check if one array is a subset of another

Reply
Thread Tools

The Easiest way to check if one array is a subset of another

 
 
Thriving K.
Guest
Posts: n/a
 
      08-04-2009
I want to find the easiest way if one array is a subset of another

for example

A b
[1,2,4,5,6,7,9] [1,3,9] =>true

A b
[1,2,4,5,6,7,9] [1,3,8] =>false
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Thriving K.
Guest
Posts: n/a
 
      08-04-2009
Oop, i already found

http://adzdavies.blogspot.com/2008/0...supersets.html

b.to_set.subset?(a.to_set)
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Gennady Bystritsky
Guest
Posts: n/a
 
      08-04-2009
PiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOi BzdXBlcmRpc2Nvbm5lY3RAaG90
bWFpbC5jb20gW21haWx0bzpzdXBlcmRpc2Nvbm5lY3RAaG90bW FpbC5jb21dDQo+IFNlbnQ6IE1v
bmRheSwgQXVndXN0IDAzLCAyMDA5IDEwOjEzIFBNDQo+IFRvOi BydWJ5LXRhbGsgTUwNCj4gU3Vi
amVjdDogVGhlIEVhc2llc3Qgd2F5IHRvIGNoZWNrIGlmIG9uZS BhcnJheSBpcyBhIHN1YnNldCBv
ZiBhbm90aGVyDQo+IA0KPiBJIHdhbnQgdG8gZmluZCB0aGUgZW FzaWVzdCB3YXkgaWYgb25lIGFy
cmF5IGlzIGEgc3Vic2V0IG9mIGFub3RoZXINCj4gDQo+IGZvci BleGFtcGxlDQo+IA0KPiAgQSAg
ICAgICAgICAgICAgICAgICAgYg0KPiBbMSwyLDQsNSw2LDcsOV 0gICAgICBbMSwzLDldID0+dHJ1
ZQ0KPiANCj4gIEEgICAgICAgICAgICAgICAgICAgIGINCj4gWz EsMiw0LDUsNiw3LDldICAgICAg
WzEsMyw4XSA9PmZhbHNlDQo+IC0tDQo+IFBvc3RlZCB2aWEgaH R0cDovL3d3dy5ydWJ5LWZvcnVt
LmNvbS8uDQoNCg0KSWYgSSB1bmRlcnN0YW5kIGNvcnJlY3RseS B3aGF0IHlvdSByZWFsbHkgd2Fu
dCwgdGhlIGZpcnN0IGV4YW1wbGUgc2hvdWxkIHByb2R1Y2UgZm Fsc2UsIGFzIGFycmF5ICJhIiBk
b2VzIG5vdCBoYXZlIDMuIEFzc3VtaW5nIHRoYXQgeW91IG1lYW 50IFsxLDIsMyw0LDUsNiw3LDld
IEkgdGhpbmsgdGhlIGZvbGxvd2luZyB3aWxsIHdvcmsgZm9yIH lvdToNCg0KKGEgJiBiKSA9PSBi
DQoNCkdlbm5hZHkuDQoNCg==

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
one enum is a subset of another Christopher C++ 10 02-02-2012 01:38 AM
What's a good way to find whether a hash is a subset of another hash (deep)? dblock Ruby 2 10-09-2011 08:37 PM
how to detect that one XML is a subset of another one? Phlip XML 6 04-23-2010 10:10 PM
easiest way to check python version? dmitrey Python 3 06-22-2009 12:50 PM
How to test if one dict is subset of another? Jay Tee Python 15 02-20-2007 09:10 PM



Advertisments