Skip to content

Instantly share code, notes, and snippets.

@edumaciel10
Created January 4, 2022 00:48
Show Gist options
  • Save edumaciel10/4b28d8aac7ec7b15a5edbf8e307650da to your computer and use it in GitHub Desktop.
Save edumaciel10/4b28d8aac7ec7b15a5edbf8e307650da to your computer and use it in GitHub Desktop.
randomWordPalindrome
const generateRandomWord = (alphabet, randomSizeNumber) => {
let word = '';
for (let i = 0; i < randomSizeNumber; i++) {
word += alphabet[Math.floor(Math.random() * alphabet.length)];
}
return word;
}
const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
const arraySize = 10000;
const randomWords = [...Array(arraySize)]
.map(() => generateRandomWord(alphabet, Math.floor(Math.random() * 3) + 3));
const palindromes = randomWords.filter(word => word === word.split('').reverse().join(''));
console.log(palindromes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment