Sha256: e0246a6ef0ebd27506dc9984a45ecaa3597c08ec90a8345fddc6f14615c420c0

Contents?: true

Size: 608 Bytes

Versions: 10

Compression:

Stored size: 608 Bytes

Contents

let stringToCharArray = (s) => {
  let len = String.length(s);
  Array.init(len, n => s.[n]);
}

let isAnagram = (base, word) => {
  if(String.length(base) != String.length(word)) {
    false
  } else {
    let base = String.lowercase(base);
    let word = String.lowercase(word);
    if(base == word) {
      false
    } else {
      let base = stringToCharArray(base);
      Array.sort(Char.compare, base);
      let word = stringToCharArray(word);
      Array.sort(Char.compare, word);
      base == word;
    }
  }
};

let anagrams = (base, candidates) => {
  List.filter(isAnagram(base), candidates);
};

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
trackler-2.2.1.175 tracks/reasonml/exercises/anagram/src/Example.re
trackler-2.2.1.174 tracks/reasonml/exercises/anagram/src/Example.re
trackler-2.2.1.173 tracks/reasonml/exercises/anagram/src/Example.re
trackler-2.2.1.172 tracks/reasonml/exercises/anagram/src/Example.re
trackler-2.2.1.171 tracks/reasonml/exercises/anagram/src/Example.re
trackler-2.2.1.170 tracks/reasonml/exercises/anagram/src/Example.re
trackler-2.2.1.169 tracks/reasonml/exercises/anagram/src/Example.re
trackler-2.2.1.167 tracks/reasonml/exercises/anagram/src/Example.re
trackler-2.2.1.166 tracks/reasonml/exercises/anagram/src/Example.re
trackler-2.2.1.165 tracks/reasonml/exercises/anagram/src/Example.re