Created
November 26, 2023 20:32
-
-
Save CSMastermind/faa7137be440d097cb4b3bb2a6c71ab1 to your computer and use it in GitHub Desktop.
Full Deletable Word Finder
This file contains 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
const fs = require('fs'); | |
const wordListPath = require('word-list'); | |
const wordArray = fs.readFileSync(wordListPath, 'utf8').split('\n'); | |
const wordSet = new Set(wordArray); | |
function findFullyDeletableWords(words) { | |
const fullyDeletableWords = new Set(); | |
words.forEach(word => { | |
console.log('Checking: ' + word); | |
let isFullyDeletable = true; | |
for (let i = 0; i < word.length; i++) { | |
let newWord = word.slice(0, i) + word.slice(i + 1); | |
//console.log('\tTrying: ' + newWord); | |
if (!words.has(newWord)) { | |
isFullyDeletable = false; | |
break; // The word is not fully deletable | |
} | |
} | |
if (isFullyDeletable) { | |
fullyDeletableWords.add(word); | |
} | |
}); | |
return Array.from(fullyDeletableWords); | |
} | |
const fullyDeletableWords = findFullyDeletableWords(wordSet); | |
console.log("Fully deletable words found:", JSON.stringify(fullyDeletableWords, null, 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment