6 kyu

Does array x contain all values within array y?

1,859 of 2,778jhoffner

Description:

We want to extend the array class so that it provides a contains_all? method. This method will always assume that an array is passed in and will return true if all values in the passed in array are present within the current array.

For example:

items = [1, 2, 3, 4, 5, 6, 7, 8, 9]

items.contains_all?([1, 2, 3]) # should == true
items.contains_all?([1, 5, 13]) # should == false because 13 is not in the items array
items = [1, 2, 3, 4, 5, 6, 7, 8, 9]

items.containsAll [1, 2, 3]  # should == true
items.containsAll [1, 5, 13] # should == false because 13 is not in the items array
items = std::vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9}

contains_all(items, {1, 2, 3})  # should == true
contains_all(items, {1, 5, 13}) # should == false because 13 is not in the items array
const items = [1, 2, 3, 4, 5, 6, 7, 8, 9];
items.containsAll([1, 2, 3]);  =>  true
items.containsAll([1, 5, 13]);  =>  false // because 13 is not in the items array
Arrays
Fundamentals

Stats:

CreatedMar 16, 2013
PublishedJun 24, 2013
Warriors Trained4392
Total Skips498
Total Code Submissions10105
Total Times Completed2778
Ruby Completions1859
CoffeeScript Completions21
C++ Completions313
JavaScript Completions514
Total Stars38
% of votes with a positive feedback rating92% of 241
Total "Very Satisfied" Votes208
Total "Somewhat Satisfied" Votes28
Total "Not Satisfied" Votes5
Ad
Contributors
  • jhoffner Avatar
  • hbakhtiyor Avatar
  • JohanWiltink Avatar
  • cliffstamp Avatar
  • SergeySinyavskiy Avatar
  • Just4FunCoder Avatar
Ad