Sha256: 68619faf95413a33af760634d2658d0a9c883e57729062bfc689e3e7c75027f1

Contents?: true

Size: 469 Bytes

Versions: 396

Compression:

Stored size: 469 Bytes

Contents

module Anagram
  extend self

  def find(subject, candidates)
    matches = Array(String).new
    candidates.each do |candidate|
      if !duplicates?(subject, candidate) && anagrams?(subject, candidate)
        matches << candidate
      end
    end
    matches
  end

  def anagrams?(subject, candidate)
    subject.downcase.chars.sort == candidate.downcase.chars.sort
  end

  def duplicates?(subject, candidate)
    subject.downcase == candidate.downcase
  end
end

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.118 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.117 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.116 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.115 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.114 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.113 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.111 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.110 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.109 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.108 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.107 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.106 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.105 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.104 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.103 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.102 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.101 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.100 tracks/crystal/exercises/anagram/src/example.cr
trackler-2.2.1.99 tracks/crystal/exercises/anagram/src/example.cr