Skip to content

Commit af6907c

Browse files
author
programmiri
committed
Add excercise Matrix
1 parent 4afb944 commit af6907c

File tree

6 files changed

+210
-0
lines changed

6 files changed

+210
-0
lines changed

matrix/.eslintrc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"root": true,
3+
"parser": "babel-eslint",
4+
"parserOptions": {
5+
"ecmaVersion": 7,
6+
"sourceType": "module"
7+
},
8+
"env": {
9+
"es6": true,
10+
"node": true,
11+
"jest": true
12+
},
13+
"extends": [
14+
"eslint:recommended",
15+
"plugin:import/errors",
16+
"plugin:import/warnings"
17+
],
18+
"rules": {
19+
"linebreak-style": "off",
20+
21+
"import/extensions": "off",
22+
"import/no-default-export": "off",
23+
"import/no-unresolved": "off",
24+
"import/prefer-default-export": "off"
25+
}
26+
}

matrix/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Matrix
2+
3+
Given a string representing a matrix of numbers, return the rows and columns of
4+
that matrix.
5+
6+
So given a string with embedded newlines like:
7+
8+
```text
9+
9 8 7
10+
5 3 2
11+
6 6 7
12+
```
13+
14+
representing this matrix:
15+
16+
```text
17+
1 2 3
18+
|---------
19+
1 | 9 8 7
20+
2 | 5 3 2
21+
3 | 6 6 7
22+
```
23+
24+
your code should be able to spit out:
25+
26+
- A list of the rows, reading each row left-to-right while moving
27+
top-to-bottom across the rows,
28+
- A list of the columns, reading each column top-to-bottom while moving
29+
from left-to-right.
30+
31+
The rows for our example matrix:
32+
33+
- 9, 8, 7
34+
- 5, 3, 2
35+
- 6, 6, 7
36+
37+
And its columns:
38+
39+
- 9, 5, 6
40+
- 8, 3, 6
41+
- 7, 2, 7
42+
43+
## Setup
44+
45+
Go through the setup instructions for Javascript to install the necessary
46+
dependencies:
47+
48+
[https://exercism.io/tracks/javascript/installation](https://exercism.io/tracks/javascript/installation)
49+
50+
## Requirements
51+
52+
Install assignment dependencies:
53+
54+
```bash
55+
$ npm install
56+
```
57+
58+
## Making the test suite pass
59+
60+
Execute the tests with:
61+
62+
```bash
63+
$ npm test
64+
```
65+
66+
In the test suites all tests but the first have been skipped.
67+
68+
Once you get a test passing, you can enable the next one by changing `xtest` to
69+
`test`.
70+
71+
## Source
72+
73+
Warmup to the `saddle-points` warmup. [http://jumpstartlab.com](http://jumpstartlab.com)
74+
75+
## Submitting Incomplete Solutions
76+
77+
It's possible to submit an incomplete solution so you can see how others have
78+
completed the exercise.

matrix/babel.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/env',
5+
{
6+
targets: {
7+
node: 'current',
8+
},
9+
useBuiltIns: false,
10+
},
11+
12+
],
13+
],
14+
};

matrix/matrix.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// This is only a SKELETON file for the 'Matrix' exercise. It's been provided as a
3+
// convenience to get you started writing code faster.
4+
//
5+
6+
export class Matrix {
7+
constructor() {
8+
throw new Error("Remove this statement and implement this function");
9+
}
10+
11+
get rows() {
12+
throw new Error("Remove this statement and implement this function");
13+
}
14+
15+
get columns() {
16+
throw new Error("Remove this statement and implement this function");
17+
}
18+
}

matrix/matrix.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Matrix } from './matrix';
2+
3+
describe('Matrix', () => {
4+
test('extract row from one number matrix', () => {
5+
expect(new Matrix('1').rows[0]).toEqual([1]);
6+
});
7+
8+
xtest('can extract row', () => {
9+
expect(new Matrix('1 2\n3 4').rows[1]).toEqual([3, 4]);
10+
});
11+
12+
xtest('extract row where numbers have different widths', () => {
13+
expect(new Matrix('1 2\n10 20').rows[1]).toEqual([10, 20]);
14+
});
15+
16+
xtest('can extract row from non-square matrix with no corresponding column', () => {
17+
expect(new Matrix('1 2 3\n4 5 6\n7 8 9\n8 7 6').rows[3]).toEqual([8, 7, 6]);
18+
});
19+
20+
xtest('extract column from one number matrix', () => {
21+
expect(new Matrix('1').columns[0]).toEqual([1]);
22+
});
23+
24+
xtest('can extract column', () => {
25+
expect(new Matrix('1 2 3\n4 5 6\n7 8 9').columns[2]).toEqual([3, 6, 9]);
26+
});
27+
28+
xtest('can extract column from non-square matrix with no corresponding row', () => {
29+
expect(new Matrix('1 2 3 4\n5 6 7 8\n9 8 7 6').columns[3]).toEqual([4, 8, 6]);
30+
});
31+
32+
xtest('can extract column from non-square matrix with more columns than rows', () => {
33+
expect(new Matrix('1 2 3\n4 5 6').columns[2]).toEqual([3, 6]);
34+
});
35+
36+
xtest('extract column where numbers have different widths', () => {
37+
expect(new Matrix('89 1903 3\n18 3 1\n9 4 800').columns[1]).toEqual([1903, 3, 4]);
38+
});
39+
});

matrix/package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "exercism-javascript",
3+
"description": "Exercism exercises in Javascript.",
4+
"author": "Katrina Owen",
5+
"private": true,
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/exercism/javascript"
9+
},
10+
"devDependencies": {
11+
"@babel/cli": "^7.5.5",
12+
"@babel/core": "^7.5.5",
13+
"@babel/preset-env": "^7.5.5",
14+
"@types/jest": "^24.0.16",
15+
"@types/node": "^12.6.8",
16+
"babel-eslint": "^10.0.2",
17+
"babel-jest": "^24.8.0",
18+
"eslint": "^6.1.0",
19+
"eslint-plugin-import": "^2.18.2",
20+
"jest": "^24.8.0"
21+
},
22+
"jest": {
23+
"modulePathIgnorePatterns": [
24+
"package.json"
25+
]
26+
},
27+
"scripts": {
28+
"test": "jest --no-cache ./*",
29+
"watch": "jest --no-cache --watch ./*",
30+
"lint": "eslint .",
31+
"lint-test": "eslint . && jest --no-cache ./* "
32+
},
33+
"license": "MIT",
34+
"dependencies": {}
35+
}

0 commit comments

Comments
 (0)