Created
March 17, 2017 19:36
-
-
Save anabastos/4014c329a0852b7aa9062606e210a9ab to your computer and use it in GitHub Desktop.
Desafio map -js4girls
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
//tendo uma matrix 4x4 multiplicar apenas os valores pares | |
var matrix = [ | |
[1, 11, 32], | |
[13, 14, 15], | |
[7, 6, 2] | |
] | |
//resultado esperado: | |
// [ | |
// [1, 11, 64], | |
// [13, 28, 15], | |
// [7, 12, 4] | |
// ] |
matriz.flat().map( cv => cv % 2 == 0 ? cv * 2 : cv)
`
<title>Tendo uma matrix 4x4 dobrar apenas os valores pares</title> <script> function main(){
var matrix = [
[1, 11, 32],
[13, 14, 15],
[7, 6, 2]
];
for(i=0;i<matrix.length;i++){
for (j=0;j<matrix[i].length;j++){
if (matrix[i][j]%2==0){
matrix[i][j]=matrix[i][j]*2;
}
}
}
document.write(matrix);
}
</script>
`
`
<title>Tendo uma matrix 4x4 dobrar apenas os valores pares</title> <script> function main(){
var matrix = [
[1, 11, 32],
[13, 14, 15],
[7, 6, 2]
];
for(i=0;i<matrix.length;i++){
for (j=0;j<matrix[i].length;j++){
if (matrix[i][j]%2==0){
matrix[i][j]=matrix[i][j]*2;
}
}
}
document.write(matrix);
}
</script>
`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Concordo plenamente com o @MarcoWorms