Last active
December 19, 2019 16:13
-
-
Save OtavioBraga/30dd30f798f71eeb94c21cdd8452769a to your computer and use it in GitHub Desktop.
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
// Código pra gerar um array com N numero | |
const getNumbers = max => [...Array(max).keys()] | |
// Gero o array com numero abaixo do 60 (0...59) | |
const numbers = getNumbers(60) | |
// Método que calcula | |
const getMultiples = ({numbers, orOperand, andOperand}) => { | |
return numbers.map(number => { | |
const orOperandResult = orOperand ? orOperand.reduce((last, operand) => { | |
if (number % operand === 0) return true | |
return last | |
}, false) : true | |
const andOperandResult = andOperand ? andOperand.reduce((last, operand) => { | |
if (number % operand === 0) return true | |
return false | |
}, false) : true | |
if (orOperandResult && andOperandResult) { | |
return number | |
} | |
return false | |
}) | |
} | |
// Chamada do método | |
const multiples = getMultiples({ | |
numbers, | |
orOperand: [3,5], | |
andOperand: [7] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment