Feat: add new Markdown parser (#39800)
and change all the challenges to new `md` format.
This commit is contained in:
committed by
GitHub
parent
a07f84c8ec
commit
0bd52f8bd1
@ -1,61 +1,63 @@
|
||||
---
|
||||
title: Identity matrix
|
||||
id: 5a23c84252665b21eecc7eb1
|
||||
title: Identity matrix
|
||||
challengeType: 5
|
||||
forumTopicId: 302290
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
An <i>identity matrix</i> is a square matrix of size \( n \times n \), where the diagonal elements are all <code>1</code>s (ones), and all the other elements are all <code>0</code>s (zeroes).
|
||||
# --description--
|
||||
|
||||
An *identity matrix* is a square matrix of size \\( n \\times n \\), where the diagonal elements are all `1`s (ones), and all the other elements are all `0`s (zeroes).
|
||||
|
||||
<ul>
|
||||
<li style="list-style: none;">\(\displaystyle I_{n}=\begin{bmatrix} 1 & 0 & 0 \cr 0 & 1 & 0 \cr 0 & 0 & 1 \cr \end{bmatrix}\)</li>
|
||||
<li style='list-style: none;'>\(\displaystyle I_{n}=\begin{bmatrix} 1 & 0 & 0 \cr 0 & 1 & 0 \cr 0 & 0 & 1 \cr \end{bmatrix}\)</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Write a function that takes a number <code>n</code> as a parameter and returns the identity matrix of order \( n \times n \).
|
||||
</section>
|
||||
# --instructions--
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
Write a function that takes a number `n` as a parameter and returns the identity matrix of order \\( n \\times n \\).
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>idMatrix</code> should be a function.
|
||||
testString: assert(typeof idMatrix=='function');
|
||||
- text: <code>idMatrix(1)</code> should return an array.
|
||||
testString: assert(Array.isArray(idMatrix(1)));
|
||||
- text: <code>idMatrix(1)</code> should return <code>[ [ 1 ] ]</code>.
|
||||
testString: assert.deepEqual(idMatrix(1),results[0]);
|
||||
- text: <code>idMatrix(2)</code> should return <code>[ [ 1, 0 ], [ 0, 1 ] ]</code>.
|
||||
testString: assert.deepEqual(idMatrix(2),results[1]);
|
||||
- text: <code>idMatrix(3)</code> should return <code>[ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ]</code>.
|
||||
testString: assert.deepEqual(idMatrix(3),results[2]);
|
||||
- text: <code>idMatrix(4)</code> should return <code>[ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ]</code>.
|
||||
testString: assert.deepEqual(idMatrix(4),results[3]);
|
||||
# --hints--
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
`idMatrix` should be a function.
|
||||
|
||||
```js
|
||||
function idMatrix(n) {
|
||||
|
||||
}
|
||||
assert(typeof idMatrix == 'function');
|
||||
```
|
||||
|
||||
</div>
|
||||
`idMatrix(1)` should return an array.
|
||||
|
||||
```js
|
||||
assert(Array.isArray(idMatrix(1)));
|
||||
```
|
||||
|
||||
### After Test
|
||||
<div id='js-teardown'>
|
||||
`idMatrix(1)` should return `[ [ 1 ] ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(idMatrix(1), results[0]);
|
||||
```
|
||||
|
||||
`idMatrix(2)` should return `[ [ 1, 0 ], [ 0, 1 ] ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(idMatrix(2), results[1]);
|
||||
```
|
||||
|
||||
`idMatrix(3)` should return `[ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(idMatrix(3), results[2]);
|
||||
```
|
||||
|
||||
`idMatrix(4)` should return `[ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ]`.
|
||||
|
||||
```js
|
||||
assert.deepEqual(idMatrix(4), results[3]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
let results=[[ [ 1 ] ],
|
||||
@ -64,23 +66,22 @@ let results=[[ [ 1 ] ],
|
||||
[ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ]]
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function idMatrix(n) {
|
||||
return Array.apply(null, new Array(n)).map(function (x, i, xs) {
|
||||
return xs.map(function (_, k) {
|
||||
return i === k ? 1 : 0;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
</section>
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function idMatrix(n) {
|
||||
return Array.apply(null, new Array(n)).map(function (x, i, xs) {
|
||||
return xs.map(function (_, k) {
|
||||
return i === k ? 1 : 0;
|
||||
})
|
||||
});
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user