Sha256: 467cf4d02606dc82220305ad789ab635f5fb3b3cc6404798ae94e42091500e3c

Contents?: true

Size: 639 Bytes

Versions: 105

Compression:

Stored size: 639 Bytes

Contents

'use strict';

function Anagram(word) {
  this.word = word;
}

Anagram.prototype.matches = function (wordList) {
  var words = Array.isArray(wordList) ? wordList : [].slice.call(arguments, 0);

  return words.filter(function (candidate) {
    return !sameWord(this.word, candidate) && isAnagram(this.word, candidate);
  }, this);
};

function sameWord(word, candidate) {
  return word.toLowerCase() === candidate.toLowerCase();
}

function isAnagram(word, candiate) {
  return normalize(word) === normalize(candiate);
}

function normalize(string) {
  return string.toLowerCase().split('').sort().toString();
}

module.exports = Anagram;

Version data entries

105 entries across 105 versions & 1 rubygems

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