Skip to content

Instantly share code, notes, and snippets.

@Octagon-simon
Created August 24, 2022 06:16
Show Gist options
  • Select an option

  • Save Octagon-simon/d4f73e91e3f10d0e388cbec065bd2557 to your computer and use it in GitHub Desktop.

Select an option

Save Octagon-simon/d4f73e91e3f10d0e388cbec065bd2557 to your computer and use it in GitHub Desktop.
function unscramble(word) {
//import dictionary
const dict = require('an-array-of-english-words');
//return the result of our logic
return(
dict.filter( item => {
//handle reoccurrences
const reOccurrence1 = {}
const reOccurrence2 = {}
//check if their lengths are equal
if(item.length === word.length){
//convert the current item to array and loop through
item.split('').forEach(letter => {
//store the number of reoccurrences of each letter
reOccurrence1[letter] = reOccurrence1[letter] + 1 || 1;
})
//convert word to array and loop through
word.split('').forEach(letter => {
//store the number of reoccurrences of each letter
reOccurrence2[letter] = reOccurrence2[letter] + 1 || 1;
})
}
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment