Does an array contain all elements from another array.
Description:
Does an array contain all the elements of another array?
Sometimes you want to know if all of the elements from one array are present in another. Sometimes your array is not a set and contains duplicate elements that you still want to account for.
Examples:
[1,2,3] contains [2,3]
[1,2,2,3,3,3] contains [2,3,3]
[1,2,2,3,3,3] does not contain [2,2,2,3,3] - too many 2's
And sometimes you need to be strict.
[1.0,2.0,3.0] does not contain [1,2,3] - Floats are not Fixnums
(But arrays may also be mixed and contain more than one object type.)
Create a method called contains_all?
which takes 2 arguments, haystack
the array you need to check through and needle
the array of elements you are looking for, and returns a boolean true
or false
.
One more thing, You should make sure your arrays are still intact after the comparison.
This kata is similar to, but stricter than http://www.codewars.com/kata/does-array-x-contain-all-values-within-array-y
Note to Translators: The original kata version is in Ruby.
Similar Kata:
Stats:
Created | Jul 15, 2015 |
Published | Jul 15, 2015 |
Warriors Trained | 789 |
Total Skips | 19 |
Total Code Submissions | 2781 |
Total Times Completed | 157 |
Ruby Completions | 157 |
Total Stars | 14 |
% of votes with a positive feedback rating | 95% of 47 |
Total "Very Satisfied" Votes | 43 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 1 |