Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desafio 2 luiz emidio #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Desafio-2-luiz-emidio
  • Loading branch information
AntaresT committed Apr 22, 2021

Verified

This commit was signed with the committer’s verified signature.
shigma Shigma
commit 341fc7f185723c339b6f9ed80d49b696c63cd8e7
25 changes: 25 additions & 0 deletions javascript/desafio-02/@AntaresT_luiz-emidio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function multiply (...matriz) {
var newMatriz = []
for (let count = matriz.length - 1, i = 0; count >= 0; count--, i++) {
if (!Array.isArray(matriz[i])) continue
var primeiroImpar = matriz[i].find(item => item % 2 == 1) || 1
let resultado = []
for (let valor of matriz[i]) {
let novoValor = valor
if (valor % 2 == 0) {
novoValor = valor * primeiroImpar
}
resultado.push(novoValor)
}
newMatriz.push(resultado)
}
return newMatriz
}

console.log(multiply([1, 3, 4], [5, 6], [0, 1]))

console.log(multiply([0, 2, 7], [5, 1], [2, 0]))

console.log(multiply([0, 1], 5, [2, 0]))

console.log(multiply(5))