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.139 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.138 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.137 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.136 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.135 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.134 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.133 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.132 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.131 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.130 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.129 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.128 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.127 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.126 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.125 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.124 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.123 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.122 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.121 tracks/javascript/exercises/anagram/example.js
trackler-2.2.1.120 tracks/javascript/exercises/anagram/example.js