Feat: add new Markdown parser (#39800)

and change all the challenges to new `md` format.
This commit is contained in:
Oliver Eyton-Williams
2020-11-27 19:02:05 +01:00
committed by GitHub
parent a07f84c8ec
commit 0bd52f8bd1
2580 changed files with 113436 additions and 111979 deletions

View File

@ -1,14 +1,16 @@
---
title: Element-wise operations
id: 599c333915e0ea32d04d4bec
title: Element-wise operations
challengeType: 5
forumTopicId: 302252
---
## Description
<section id='description'>
# --description--
Implement basic element-wise matrix-matrix and scalar-matrix operations.
<strong>Implement:</strong>
**Implement:**
<ul>
<li>addition</li>
<li>subtraction</li>
@ -16,44 +18,171 @@ Implement basic element-wise matrix-matrix and scalar-matrix operations.
<li>division</li>
<li>exponentiation</li>
</ul>
The first parameter will be the operation to be performed, for example, "m_add" for matrix addition and "s_add" for scalar addition. The second and third parameters will be the matrices on which the operations are to be performed.
</section>
## Instructions
<section id='instructions'>
# --hints--
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: <code>operation</code> should be a function.
testString: assert(typeof operation === 'function');
- text: <code>operation("m_add",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[2,4],[6,8]]</code>.
testString: assert.deepEqual(operation('m_add', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[2, 4], [6, 8]]);
- text: <code>operation("s_add",[[1,2],[3,4]],2)</code> should return <code>[[3,4],[5,6]]</code>.
testString: assert.deepEqual(operation('s_add', [[1, 2], [3, 4]], 2), [[3, 4], [5, 6]]);
- text: <code>operation("m_sub",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[0,0],[0,0]]</code>.
testString: assert.deepEqual(operation('m_sub', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[0, 0], [0, 0]]);
- text: <code>operation("m_mult",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,4],[9,16]]</code>.
testString: assert.deepEqual(operation('m_mult', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 4], [9, 16]]);
- text: <code>operation("m_div",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,1],[1,1]]</code>.
testString: assert.deepEqual(operation('m_div', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 1], [1, 1]]);
- text: <code>operation("m_exp",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,4],[27,256]]</code>.
testString: assert.deepEqual(operation('m_exp', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 4], [27, 256]]);
- text: <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>.
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]]);
`operation` should be a function.
```js
assert(typeof operation === 'function');
```
</section>
`operation("m_add",[[1,2],[3,4]],[[1,2],[3,4]])` should return `[[2,4],[6,8]]`.
## Challenge Seed
<section id='challengeSeed'>
```js
assert.deepEqual(
operation(
'm_add',
[
[1, 2],
[3, 4]
],
[
[1, 2],
[3, 4]
]
),
[
[2, 4],
[6, 8]
]
);
```
<div id='js-seed'>
`operation("s_add",[[1,2],[3,4]],2)` should return `[[3,4],[5,6]]`.
```js
assert.deepEqual(
operation(
's_add',
[
[1, 2],
[3, 4]
],
2
),
[
[3, 4],
[5, 6]
]
);
```
`operation("m_sub",[[1,2],[3,4]],[[1,2],[3,4]])` should return `[[0,0],[0,0]]`.
```js
assert.deepEqual(
operation(
'm_sub',
[
[1, 2],
[3, 4]
],
[
[1, 2],
[3, 4]
]
),
[
[0, 0],
[0, 0]
]
);
```
`operation("m_mult",[[1,2],[3,4]],[[1,2],[3,4]])` should return `[[1,4],[9,16]]`.
```js
assert.deepEqual(
operation(
'm_mult',
[
[1, 2],
[3, 4]
],
[
[1, 2],
[3, 4]
]
),
[
[1, 4],
[9, 16]
]
);
```
`operation("m_div",[[1,2],[3,4]],[[1,2],[3,4]])` should return `[[1,1],[1,1]]`.
```js
assert.deepEqual(
operation(
'm_div',
[
[1, 2],
[3, 4]
],
[
[1, 2],
[3, 4]
]
),
[
[1, 1],
[1, 1]
]
);
```
`operation("m_exp",[[1,2],[3,4]],[[1,2],[3,4]])` should return `[[1,4],[27,256]]`.
```js
assert.deepEqual(
operation(
'm_exp',
[
[1, 2],
[3, 4]
],
[
[1, 2],
[3, 4]
]
),
[
[1, 4],
[27, 256]
]
);
```
`operation("m_add",[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]])` should return `[[10,12,14,16],[18,20,22,24]]`.
```js
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]
]
);
```
# --seed--
## --seed-contents--
```js
function operation(op, arr1, arr2) {
@ -61,15 +190,7 @@ function operation(op, arr1, arr2) {
}
```
</div>
</section>
## Solution
<section id='solution'>
# --solutions--
```js
function operation(op, arr1, arr2) {
@ -89,7 +210,4 @@ function operation(op, arr1, arr2) {
}
return arr1;
}
```
</section>