Created
August 24, 2022 06:16
-
-
Save Octagon-simon/d4f73e91e3f10d0e388cbec065bd2557 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 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