Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
17 changes: 16 additions & 1 deletion lib/array_intersection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
def intersection(list1, list2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

raise NotImplementedError, "Intersection not implemented"
hash = {}
intersect = []

list1.each do |item|
hash[item] = true
end

list2.each do |item|
if hash[item]
intersect << item
end
end

return intersect


end
26 changes: 23 additions & 3 deletions lib/palindrome_permutation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@

def palindrome_permutation?(string)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

raise NotImplementedError, "palindrome_permutation? not implemented"
end
if string.empty?
return true
end

hash = {}
array = string.chars

array.each do |char|
if hash[char]
hash[char] += 1
else
hash[char] = 1
end
end

odd = 0

hash.each do |key, value|
odd += 1 if value % 2 != 0
end

odd > 1 ? false : true
end
21 changes: 20 additions & 1 deletion lib/permutations.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@

def permutations?(string1, string2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail for heelo and hello. You should also count the number of each letter in each string.

raise NotImplementedError, "permutations? not implemented"

return true if string1.empty? || string2.empty?
return false if string1.length != string2.length

array1 = string1.chars
array2 = string2.chars

hash = {}

array1.each do |char|
hash[char] = true
end

array2.each do |char|
if hash[char] == nil
return false
end
end

return true
end
6 changes: 3 additions & 3 deletions test/palindrome_permutation_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,5 +19,5 @@

it "will return false for raceca" do
expect(palindrome_permutation?("raceca")).must_equal false
end
end
end
end
2 changes: 1 addition & 1 deletion test/permutations_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down