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
15 changes: 14 additions & 1 deletion lib/array_intersection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
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"
nums_array = []
nums_hash = {}

list1.each do |nums|
nums_hash[nums] = 0
end

list2.each do |nums|
if nums_hash[nums]
nums_array << nums
end
end

return nums_array
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.

👍

raise NotImplementedError, "palindrome_permutation? not implemented"
palindrome_hash = {}
result_array = []

string.each_char do |char|
if palindrome_hash[char]
palindrome_hash[char] += 1
else
palindrome_hash[char] = 1
end
end

string.each_char do |char|
if palindrome_hash[char].odd?
result_array << char
end
end

return result_array.length <= 1
end
20 changes: 19 additions & 1 deletion lib/permutations.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@

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"
permutations_hash = {}

string1.each_char do |char|
if permutations_hash[char]
permutations_hash[char] += 1
else
permutations_hash[char] = 1
end
end

string2.each_char do |char|
if permutations_hash[char] && permutations_hash[char] > 0
permutations_hash[char] -= 1
else
return false
end
end

return permutations_hash.values.all?(0)
end
2 changes: 1 addition & 1 deletion 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 Down
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