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
16 changes: 15 additions & 1 deletion lib/array_intersection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
def intersection(list1, list2)
raise NotImplementedError, "Intersection not implemented"
count_hash = {}
result = []

list1.each do |number|
count_hash[number] = true
end

list2.each do |number|
if count_hash[number] == true
result << number
end
end

return result

end
19 changes: 18 additions & 1 deletion lib/palindrome_permutation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@

def palindrome_permutation?(string)

Choose a reason for hiding this comment

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

This doesn't seem to work.

raise NotImplementedError, "palindrome_permutation? not implemented"
letter_hash = {}

string.split("").each do |letter|
if letter_hash[letter] == nil
letter_hash[letter] = 1
else
letter_hash[letter] += 1
end
end

midpoint = 0
letter_hash.each_value do |times|
if times % 2 != 0
midpoint += 0
end
end
Comment on lines +14 to +18

Choose a reason for hiding this comment

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

You would do better here to see how many letters appear an odd number of times.

Copy link
Author

@sharonkeikei sharonkeikei Apr 2, 2020

Choose a reason for hiding this comment

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

Sorry about that, Chris! I had a typo in my code. so it should be
midpoint += 1 instead of midpoint += 0
I run rake file after that seems to fix the failures, would that be consider working for this method? Just wondering. Thanks!

`def palindrome_permutation?(string)
letter_hash = {}

string.split("").each do |letter|
if letter_hash[letter] == nil
letter_hash[letter] = 1
else
letter_hash[letter] += 1
end
end

midpoint = 0
letter_hash.each_value do |times|
if times % 2 != 0
midpoint += 1
end
end
return midpoint <= 1
end
`


return midpoint <= 1
end
26 changes: 25 additions & 1 deletion lib/permutations.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@

def permutations?(string1, string2)

Choose a reason for hiding this comment

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

👍

raise NotImplementedError, "permutations? not implemented"
word_hash = {}

string1.split("").each do |letter|
if word_hash[letter] == nil
word_hash[letter] = 1
else
word_hash[letter] += 1
end
end

string2.split("").each do |letter|
if word_hash[letter] == nil
return false
else
word_hash[letter] -= 1
end
end

word_hash.each_value do |times|
if times != 0
return false
end
end

return true
end