You can use a regular expression to match words which contain different letters. Here's an example implementation:
index.tsx764 chars22 lines
The containsDifferentLetters
function takes a word as input and uses a Set to count the number of unique characters in the word. If the number of unique characters is not equal to the length of the word, then the word contains different letters.
The findWordsWithDifferentLetters
function takes an array of words as input and uses the filter
method to return an array of all the words that contain different letters.
In the example usage, the words
array contains five words, and findWordsWithDifferentLetters
returns an array containing only the words 'unique' and 'letters', which contain different letters.
gistlibby LogSnag