Last active
January 7, 2020 00:16
-
-
Save anabastos/d33e5c850d6250399c0d731ed2fb4b84 to your computer and use it in GitHub Desktop.
Dado um número aleatório, retornar todos os números PRIMOS entre 0 e o número escolhido
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 criaArrayPrimos = x => | |
criaArray(x) | |
.slice(2) | |
.filter(checaFatores) | |
const criaArray = tamanho => Array.from({ length: tamanho }, (el, index) => index) | |
const checaFatores = n => | |
criaArray(maiorDivisor(n)) | |
.slice(2) | |
.every(m => n % m !== 0) | |
const maiorDivisor = x => Math.ceil(Math.sqrt(x + 1)) | |
console.log(criaArrayPrimos(40)) //[ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment