-
Notifications
You must be signed in to change notification settings - Fork 0
/
solve.mjs
18 lines (16 loc) · 823 Bytes
/
solve.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import wordList from 'an-array-of-english-words';
const solve = (keyLetter, otherLetters, minLength = 4) => {
return wordList.filter(word => {
const sanitizedKeyLetter = keyLetter.toLowerCase();
const sanitizedOtherLetters = otherLetters.map(letter => letter.toLowerCase());
const sanitizedWord = word.replace(/[^a-zA-Z]/g, '').toLowerCase();
const sanitizedRequiredLetters = sanitizedOtherLetters.concat(sanitizedKeyLetter);
const isComposedOfRequiredLetters = sanitizedWord.split('').every(letter => {
return sanitizedRequiredLetters.includes(letter);
});
const hasKeyLetter = sanitizedWord.includes(sanitizedKeyLetter);
const isLongEnough = sanitizedWord.length >= minLength;
return isComposedOfRequiredLetters && hasKeyLetter && isLongEnough;
});
};
export default solve;