Last active
October 8, 2020 20:55
-
-
Save diegotauchert/d9b7248b7de4053edf28b44f8731f8a5 to your computer and use it in GitHub Desktop.
Script that creates an array with 10000 random words between 3 and 5 characteres, and returns the words that are palindromes in that array
This file contains hidden or 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 main = () => { | |
| var characters = 'abcdefghijklmnopqrstuvwxyz'; | |
| var charactersLength = characters.length; | |
| var words = []; | |
| var wordsPalindromes = []; | |
| for(var j = 0; j < 10000; j++){ | |
| var wordLength = Math.floor(Math.random() * (5 - 3 + 1) ) + 3; | |
| var word = ''; | |
| for ( var i = 0; i < wordLength; i++ ) { | |
| word += characters.charAt(Math.floor(Math.random() * charactersLength)); | |
| } | |
| words.push(word); | |
| if(word.split('').reverse().join('') == word) { | |
| wordsPalindromes.push(word); | |
| } | |
| } | |
| return wordsPalindromes; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment