Skip to content

Instantly share code, notes, and snippets.

@OtavioBraga
Last active December 19, 2019 16:13
Show Gist options
  • Save OtavioBraga/30dd30f798f71eeb94c21cdd8452769a to your computer and use it in GitHub Desktop.
Save OtavioBraga/30dd30f798f71eeb94c21cdd8452769a to your computer and use it in GitHub Desktop.
// 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