Last active
March 17, 2017 14:50
-
-
Save Woodsphreaker/6188de4a5f22bb004826107f5724514a 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
const matrix = [[2,4,6,8],[12,14,16,18],[20,24,28,32],[32,34,36,38],[42,44,46,48]]; | |
const exp = matrix[0]; | |
const arrNumbers = matrix.slice(1); | |
const props = [ | |
(number, _i) => (number * exp[_i]), | |
(number, _i) => (number / exp[_i]), | |
(number, _i) => (number - exp[_i]), | |
(number, _i) => (number + exp[_i]) | |
]; | |
const op = (arr, _i) => arr.map(_a => props[_i](_a, _i)); | |
const prep = arrNumbers.map((_a, _b) => op(_a, _b)); | |
const concat = [].concat(exp, ...prep); | |
const sum = concat.reduce((_a, _b) => _a + _b); | |
console.log(concat, sum); |
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
Desafio dos operadores básicos | |
Dado o Array matrix, utilizar a primeira posição como indice dos operadores basicos | |
[2, 4, 6, 8] | |
[2] deve multiplicar cada posição [2] * [12, 14, 16, 18] => [24, 28, 32, 36] | |
[4] deve dividir cada posição [4] / [20, 24, 28, 32] => [5, 6, 7, 8] | |
[6] deve subtrair cada posição [6] - [32, 34, 36, 38] => [26, 28, 30, 32] | |
[8] deve somar cada posição [8] + [42, 44, 46, 48] => [50, 52, 54, 56] | |
Quando todos os calculos forem feitos, os novos valores do array devem ser somados juntamente com o [2, 4, 6, 8] ou seja: | |
soma ([[2, 4, 6, 8], [24, 28, 32, 36], [5, 6, 7, 8], [26, 28, 30, 32], [50, 52, 54, 56]]) = 494 | |
O resultado final do cálculo é 494 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gostei do desafio
https://gist.github.com/lubien/2c7937ccb3c89b3017e5510ca83d7de2