Created
August 12, 2016 22:15
-
-
Save jordancalder/9f4ca0f6c004bdfd18b79ecb1eea214b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function meagrams(word, cb){ | |
var grams = []; | |
for(w in words){ | |
if(word.length === words[w].length){ | |
var diff1 = 0; | |
var diff2 = 0; | |
var word1 = word.split('').sort().join('') | |
var word2 = words[w].split('').sort().join('') | |
for(var i = 0; i < word.length; i++){ | |
if(occurances(words[w][i], words[w]) !== occurances(words[w][i], word)) diff1++; | |
if(word1[i] !== word2[i]) diff2++; | |
} | |
if(diff1 === 1 || diff2 === 1) grams.push(words[w]) | |
} | |
} | |
cb(grams); | |
} |
can you please mention the problem statement for this algorithm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function occurances(w, word){ var c = 0 for(var i = 0; i < word.length; i++){ if(w === word[i]){ c++; } } return c; }