Sha256: 466f153029c3364cdc2efde1b1fa8ae0d863b8f7098fb3d6a959d2ae52aacf5b
Contents?: true
Size: 542 Bytes
Versions: 211
Compression:
Stored size: 542 Bytes
Contents
const sameWord = (word, candidate) => word.toLowerCase() === candidate.toLowerCase(); const isAnagram = (word, candiate) => normalize(word) === normalize(candiate); const normalize = str => str.toLowerCase().split('').sort().join(); export default class Anagram { constructor(word) { this.word = word; } matches(words) { words = Array.isArray(words) ? words : Array.from(arguments); return words.filter(candidate => { return !sameWord(this.word, candidate) && isAnagram(this.word, candidate); }); } }
Version data entries
211 entries across 211 versions & 1 rubygems