dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
70 lines
1.3 KiB
Markdown
70 lines
1.3 KiB
Markdown
---
|
|
id: 68ee9e3066cfd4eb2328e8a6
|
|
title: "Challenge 87: Matrix Builder"
|
|
challengeType: 28
|
|
dashedName: challenge-87
|
|
---
|
|
|
|
# --description--
|
|
|
|
Given two integers (a number of rows and a number of columns), return a matrix (an array of arrays) filled with zeros (`0`) of the given size.
|
|
|
|
For example, given `2` and `3`, return:
|
|
|
|
```json
|
|
[
|
|
[0, 0, 0],
|
|
[0, 0, 0]
|
|
]
|
|
```
|
|
|
|
# --hints--
|
|
|
|
`buildMatrix(2, 3)` should return `[[0, 0, 0], [0, 0, 0]]`.
|
|
|
|
```js
|
|
assert.deepEqual(buildMatrix(2, 3), [[0, 0, 0], [0, 0, 0]]);
|
|
```
|
|
|
|
`buildMatrix(3, 2)` should return `[[0, 0], [0, 0], [0, 0]]`.
|
|
|
|
```js
|
|
assert.deepEqual(buildMatrix(3, 2), [[0, 0], [0, 0], [0, 0]]);
|
|
```
|
|
|
|
`buildMatrix(4, 3)` should return `[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]`.
|
|
|
|
```js
|
|
assert.deepEqual(buildMatrix(4, 3), [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]);
|
|
```
|
|
|
|
`buildMatrix(9, 1)` should return `[[0], [0], [0], [0], [0], [0], [0], [0], [0]]`.
|
|
|
|
```js
|
|
assert.deepEqual(buildMatrix(9, 1), [[0], [0], [0], [0], [0], [0], [0], [0], [0]]);
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
function buildMatrix(rows, cols) {
|
|
|
|
return rows;
|
|
}
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
function buildMatrix(rows, cols) {
|
|
const matrix = [];
|
|
for (let i = 0; i < rows; i++) {
|
|
const row = new Array(cols).fill(0);
|
|
matrix.push(row);
|
|
}
|
|
return matrix;
|
|
}
|
|
```
|