Created
November 29, 2018 22:48
-
-
Save cored/00fed6bc706df29fab6a720359c98c04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "minitest/autorun" | |
module Anagram | |
def self.call(words, str) | |
words.select do |word| | |
word if (word.chars.sort == str.chars.sort) && word != str | |
end | |
end | |
end | |
describe Anagram do | |
it "when we pass an empty string" do | |
words = ["apple", "orange"] | |
str = "" | |
Anagram.call(words, str).must_equal [] | |
end | |
it "when we pass an actual anagram word within the words list" do | |
words = ["kinship"] | |
str = "pinkish" | |
Anagram.call(words, str).must_equal ["kinship"] | |
end | |
it "when we use a bigger list" do | |
words = ["kinship", "pinkish", "enlist", "inlets", "listen", "silent", "boaster", "boaters", "borates", "fresher", "refresh", "sinks", "skins", "knits", "stink", "rots", "sort"] | |
str = "enlist" | |
Anagram.call(words, str).must_equal ["inlets", "listen", "silent"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment