Skip to content

Instantly share code, notes, and snippets.

@jordancalder
Created August 12, 2016 22:15
Show Gist options
  • Save jordancalder/9f4ca0f6c004bdfd18b79ecb1eea214b to your computer and use it in GitHub Desktop.
Save jordancalder/9f4ca0f6c004bdfd18b79ecb1eea214b to your computer and use it in GitHub Desktop.
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);
}
@jordancalder
Copy link
Author

function occurances(w, word){ var c = 0 for(var i = 0; i < word.length; i++){ if(w === word[i]){ c++; } } return c; }

@AlfAinTech
Copy link

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