diff --git a/lib/array_intersection.rb b/lib/array_intersection.rb index ac8771f..ad17186 100644 --- a/lib/array_intersection.rb +++ b/lib/array_intersection.rb @@ -1,3 +1,3 @@ def intersection(list1, list2) - raise NotImplementedError, "Intersection not implemented" + intersect = list1 & list2 end \ No newline at end of file diff --git a/lib/palindrome_permutation.rb b/lib/palindrome_permutation.rb index f113692..102c245 100644 --- a/lib/palindrome_permutation.rb +++ b/lib/palindrome_permutation.rb @@ -1,4 +1,17 @@ def palindrome_permutation?(string) - raise NotImplementedError, "palindrome_permutation? not implemented" -end \ No newline at end of file + + letter_hash = {} + string.chars.map do |char| + letter_hash["#{char}"] = string.count(char) + end + + odd_count = 0 + letter_hash.each do |key, value| + value.odd? ? (odd_count += 1) : next + end + + odd_count > 1 ? (return false) : (return true) + +end + diff --git a/lib/permutations.rb b/lib/permutations.rb index 3b08381..4d696ee 100644 --- a/lib/permutations.rb +++ b/lib/permutations.rb @@ -1,4 +1,14 @@ def permutations?(string1, string2) - raise NotImplementedError, "permutations? not implemented" + return false if string1.length != string2.length + + string1.chars.each do |char| + if string2.include?(char) + string1.slice!(char) + string2.slice!(char) + end + end + + return true if string1.empty? && string2.empty? + return false end \ No newline at end of file diff --git a/test/palindrome_permutation_test.rb b/test/palindrome_permutation_test.rb index e9119de..984b333 100644 --- a/test/palindrome_permutation_test.rb +++ b/test/palindrome_permutation_test.rb @@ -1,6 +1,6 @@ require_relative "test_helper" -xdescribe "palindrome_permutation?" do +describe "palindrome_permutation?" do it "will work for hello" do expect(palindrome_permutation?("hello")).must_equal false end diff --git a/test/permutations_test.rb b/test/permutations_test.rb index 79da2f6..28c50ca 100644 --- a/test/permutations_test.rb +++ b/test/permutations_test.rb @@ -1,6 +1,6 @@ require_relative "test_helper" -xdescribe "permutations?" do +describe "permutations?" do it "returns true for empty string" do expect(permutations?("", "")).must_equal true end @@ -13,7 +13,7 @@ expect(permutations?("pasta", "atsap")).must_equal true end - it "returns true for 'pizza', 'pizza'" do + it "returns false for 'pizza', 'pasta'" do expect(permutations?("pizza", "pasta")).must_equal false end