Skip to content

Instantly share code, notes, and snippets.

@dmehrotra
Created September 5, 2013 16:53
Show Gist options
  • Save dmehrotra/6452917 to your computer and use it in GitHub Desktop.
Save dmehrotra/6452917 to your computer and use it in GitHub Desktop.
class Anagram
def initialize(word)
@characters =[]
word.each_char{|x| @characters<<x}
end
def convert
anagrams = []
@characters.permutation.each {|x| anagrams << x.join}
p anagrams
end
end
dog = Anagram.new('dog')
dog.convert
require 'rspec'
require_relative 'anagram'
describe Anagram do
describe 'Anagram = to' do
it 'expects :to: to return ot' do
expect(Anagram.new('to').convert).to eql('ot')
end
end
describe 'Anagram: dog' do
it 'expects :dog: to return an array of anagrams' do
expect(Anagram.new('dog').convert).to eql(["dog", "dgo", "odg", "ogd", "gdo", "god"])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment