Created
January 4, 2022 00:48
-
-
Save edumaciel10/4b28d8aac7ec7b15a5edbf8e307650da to your computer and use it in GitHub Desktop.
randomWordPalindrome
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 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