Skip to content

Anagram

Exercism

条件

  1. 与えられた単語に対してアナグラムを見つける
  2. 大文字と小文字は区別しない
  3. 同じ単語はアナグラムとして扱わない

初期コード

use std::collections::HashSet;
pub fn anagrams_for<'a>(word: &str, possible_anagrams: &'a [&str]) -> HashSet<&'a str> {
todo!("For the '{word}' word find anagrams among the following words: {possible_anagrams:?}");
}

考察

  • 条件2より、全て小文字に変換する
  • 一致するやつは除く
  • 各単語の文字をsortして一致するか?

学んだこと

  • filterの返り値の型
    • Filter