2018-10-08 17:34:43 +00:00
---
title: Element-wise operations
id: 599c333915e0ea32d04d4bec
challengeType: 5
2018-10-10 20:20:40 +00:00
videoUrl: ''
localeTitle: Operaciones de elementos sabios
2018-10-08 17:34:43 +00:00
---
## Description
2018-10-10 20:20:40 +00:00
< section id = "description" >< p > Implementar operaciones básicas de matriz de matriz de elementos y matriz escalar. </ p >< p > Implementar: </ p >< p > :: * Además </p><p> :: * resta </ p >< p > :: * multiplicación </p><p> :: * división </ p >< p > :: * exponenciación </ p >< p > El primer parámetro será la operación a realizar, por ejemplo: " m_add" para la adición de matriz y " s_add" para la adición escalar. Los parámetros segundo y tercero serán las matrices sobre las que se realizarán las operaciones. </ p ></ section >
2018-10-08 17:34:43 +00:00
## Instructions
2018-10-10 20:20:40 +00:00
< section id = "instructions" >
2018-10-08 17:34:43 +00:00
< / section >
## Tests
< section id = 'tests' >
```yml
tests:
- text: < code > operation</ code > es una función.
testString: 'assert(typeof operation === "function", "< code > operation< / code > is a function.");'
2018-10-10 20:20:40 +00:00
- text: '< code > operation(" m_add" ,[[1,2],[3,4]],[[1,2],[3,4]])</ code > debe devolver < code > [[2,4],[6,8]]</ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert.deepEqual(operation("m_add", [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[2, 4], [6, 8]], "< code > operation("m_add",[[1,2],[3,4]],[[1,2],[3,4]])< / code > should return < code > [[2,4],[6,8]]< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > operation(" s_add" ,[[1,2],[3,4]],[[1,2],[3,4]])</ code > debe devolver < code > [[3,4],[5,6]]</ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert.deepEqual(operation("s_add", [[1, 2], [3, 4]], 2), [[3, 4], [5, 6]], "< code > operation("s_add",[[1,2],[3,4]],[[1,2],[3,4]])< / code > should return < code > [[3,4],[5,6]]< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > operation(" m_sub" ,[[1,2],[3,4]],[[1,2],[3,4]])</ code > debe devolver < code > [[0,0],[0,0]]</ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert.deepEqual(operation("m_sub", [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[0, 0], [0, 0]], "< code > operation("m_sub",[[1,2],[3,4]],[[1,2],[3,4]])< / code > should return < code > [[0,0],[0,0]]< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > operation(" m_mult" ,[[1,2],[3,4]],[[1,2],[3,4]])</ code > debe devolver < code > [[1,4],[9,16]]</ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert.deepEqual(operation("m_mult", [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 4], [9, 16]], "< code > operation("m_mult",[[1,2],[3,4]],[[1,2],[3,4]])< / code > should return < code > [[1,4],[9,16]]< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > operation(" m_div" ,[[1,2],[3,4]],[[1,2],[3,4]])</ code > debe devolver < code > [[1,1],[1,1]]</ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert.deepEqual(operation("m_div", [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 1], [1, 1]], "< code > operation("m_div",[[1,2],[3,4]],[[1,2],[3,4]])< / code > should return < code > [[1,1],[1,1]]< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > operation(" m_exp" ,[[1,2],[3,4]],[[1,2],[3,4]])</ code > debe devolver < code > [[1,4],[27,256]]</ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert.deepEqual(operation("m_exp", [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 4], [27, 256]], "< code > operation("m_exp",[[1,2],[3,4]],[[1,2],[3,4]])< / code > should return < code > [[1,4],[27,256]]< / code > .");'
2018-10-10 20:20:40 +00:00
- text: '< code > operation(" m_add" ,[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]])</ code > debe devolver < code > [[10,12,14,16],[18,20,22,24]]</ code > .'
2018-10-08 17:34:43 +00:00
testString: 'assert.deepEqual(operation("m_add", [[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]), [[10, 12, 14, 16], [18, 20, 22, 24]], "< code > operation("m_add",[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]])< / code > should return < code > [[10,12,14,16],[18,20,22,24]]< / code > .");'
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
function operation (op, arr1, arr2) {
// Good luck!
}
2018-10-10 20:20:40 +00:00
2018-10-08 17:34:43 +00:00
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2018-10-10 20:20:40 +00:00
// solution required
2018-10-08 17:34:43 +00:00
```
< / section >