@@ -0,0 +1,14 @@ | |||
{ | |||
"root": true, | |||
"extends": "@exercism/eslint-config-javascript", | |||
"env": { | |||
"jest": true | |||
}, | |||
"overrides": [ | |||
{ | |||
"files": [".meta/proof.ci.js", ".meta/exemplar.js", "*.spec.js"], | |||
"excludedFiles": ["custom.spec.js"], | |||
"extends": "@exercism/eslint-config-javascript/maintainers" | |||
} | |||
] | |||
} |
@@ -0,0 +1,10 @@ | |||
{ | |||
"blurb": "Count the rectangles in an ASCII diagram.", | |||
"authors": ["MattH-be"], | |||
"contributors": ["ankorGH", "SleeplessByte", "tejasbubane", "xarxziux"], | |||
"files": { | |||
"solution": ["rectangles.js"], | |||
"test": ["rectangles.spec.js"], | |||
"example": [".meta/proof.ci.js"] | |||
} | |||
} |
@@ -0,0 +1 @@ | |||
{"track":"javascript","exercise":"rectangles","id":"2e7ea202159b490589c046d95f1d150a","url":"https://exercism.org/tracks/javascript/exercises/rectangles","handle":"on6qd","is_requester":true,"auto_approve":false} |
@@ -0,0 +1,4 @@ | |||
node_modules/ | |||
node_modules/ | |||
node_modules/ | |||
node_modules/ |
@@ -0,0 +1 @@ | |||
audit=false |
@@ -0,0 +1,73 @@ | |||
# Help | |||
## Running the tests | |||
## Setup | |||
Go through the setup [instructions for JavaScript][docs-exercism-javascript] to install the necessary dependencies. | |||
## Requirements | |||
Install assignment dependencies: | |||
```shell | |||
# Using npm | |||
npm install | |||
# Alternatively using yarn | |||
yarn | |||
``` | |||
## Making the test suite pass | |||
All exercises come with a test suite to help you validate your solution before submitting. | |||
You can execute these tests by opening a command prompt in the exercise's directory, and then running: | |||
```bash | |||
# Using npm | |||
npm test | |||
# Alternatively using yarn | |||
yarn test | |||
``` | |||
In some test suites all tests but the first have been skipped. | |||
Once you get a test passing, you can enable the next one by changing `xtest` to `test`. | |||
## Writing custom tests | |||
If you wish to write additional, custom, tests, create a new file `custom.spec.js`, and submit it with your solution together with the new file: | |||
```shell | |||
exercism submit numbers.js custom.spec.js | |||
``` | |||
[docs-exercism-javascript]: https://exercism.org/docs/tracks/javascript/installation | |||
## Submitting your solution | |||
You can submit your solution using the `exercism submit rectangles.js` command. | |||
This command will upload your solution to the Exercism website and print the solution page's URL. | |||
It's possible to submit an incomplete solution which allows you to: | |||
- See how others have completed the exercise | |||
- Request help from a mentor | |||
## Need to get help? | |||
If you'd like help solving the exercise, check the following pages: | |||
- The [JavaScript track's documentation](https://exercism.org/docs/tracks/javascript) | |||
- [Exercism's support channel on gitter](https://gitter.im/exercism/support) | |||
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) | |||
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. | |||
To get help if you're having trouble, you can use one of the following resources: | |||
- [Gitter](https://gitter.im/exercism/support) is Exercism's Gitter room; go here to get support and ask questions if you face any issues with downloading or submitting your exercises. | |||
- [/r/javascript](https://www.reddit.com/r/javascript) is the Javascript subreddit. | |||
- [StackOverflow](https://stackoverflow.com/questions/tagged/javascript+exercism) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. | |||
- [Github issue tracker](https://github.com/exercism/javascript/issues) is where we track our development and maintainance of Javascript exercises in exercism. But if none of the above links help you, feel free to post an issue here. |
@@ -0,0 +1,21 @@ | |||
MIT License | |||
Copyright (c) 2021 Exercism | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all | |||
copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
SOFTWARE. |
@@ -0,0 +1,82 @@ | |||
# Rectangles | |||
Welcome to Rectangles on Exercism's JavaScript Track. | |||
If you need help running the tests or submitting your code, check out `HELP.md`. | |||
## Instructions | |||
Count the rectangles in an ASCII diagram like the one below. | |||
```text | |||
+--+ | |||
++ | | |||
+-++--+ | |||
| | | | |||
+--+--+ | |||
``` | |||
The above diagram contains 6 rectangles: | |||
```text | |||
+-----+ | |||
| | | |||
+-----+ | |||
``` | |||
```text | |||
+--+ | |||
| | | |||
| | | |||
| | | |||
+--+ | |||
``` | |||
```text | |||
+--+ | |||
| | | |||
+--+ | |||
``` | |||
```text | |||
+--+ | |||
| | | |||
+--+ | |||
``` | |||
```text | |||
+--+ | |||
| | | |||
+--+ | |||
``` | |||
```text | |||
++ | |||
++ | |||
``` | |||
You may assume that the input is always a proper rectangle (i.e. the length of | |||
every line equals the length of the first line). | |||
## Source | |||
### Created by | |||
- @MattH-be | |||
### Contributed to by | |||
- @ankorGH | |||
- @SleeplessByte | |||
- @tejasbubane | |||
- @xarxziux |
@@ -0,0 +1,15 @@ | |||
module.exports = { | |||
presets: [ | |||
[ | |||
'@babel/preset-env', | |||
{ | |||
targets: { | |||
node: 'current', | |||
}, | |||
useBuiltIns: 'entry', | |||
corejs: '3.19', | |||
}, | |||
], | |||
], | |||
plugins: ['@babel/plugin-syntax-bigint'], | |||
}; |
@@ -0,0 +1,31 @@ | |||
{ | |||
"name": "@exercism/javascript-rectangles", | |||
"description": "Exercism exercises in Javascript.", | |||
"author": "Katrina Owen", | |||
"private": true, | |||
"license": "MIT", | |||
"repository": { | |||
"type": "git", | |||
"url": "https://github.com/exercism/javascript", | |||
"directory": "exercises/practice/rectangles" | |||
}, | |||
"devDependencies": { | |||
"@babel/cli": "^7.16.0", | |||
"@babel/core": "^7.16.0", | |||
"@babel/plugin-syntax-bigint": "^7.8.3", | |||
"@babel/preset-env": "^7.16.0", | |||
"@exercism/eslint-config-javascript": "^0.5.0", | |||
"@types/jest": "^26.0.24", | |||
"@types/node": "^16.11.6", | |||
"babel-jest": "^27.3.1", | |||
"core-js": "^3.19.1", | |||
"eslint": "^7.32.0", | |||
"jest": "^26.6.3" | |||
}, | |||
"dependencies": {}, | |||
"scripts": { | |||
"test": "jest --no-cache ./*", | |||
"watch": "jest --no-cache --watch ./*", | |||
"lint": "eslint ." | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
// | |||
// This is only a SKELETON file for the 'Rectangles' exercise. It's been provided as a | |||
// convenience to get you started writing code faster. | |||
// | |||
function testRectangle(input,i,j) { | |||
} | |||
export function count(input) { | |||
var result = 0; | |||
for(var i = 0; i < input.length; i++){ | |||
var line = input[i]; | |||
for(var j = 0; j < line.length; j++){ | |||
if(line[j] != "+") continue; | |||
for(var nx = j + 1; nx < line.length; nx++){ | |||
if(line[nx] == "-") continue; | |||
if(line[nx] != "+") break; | |||
for(var ny = i + 1; ny < input.length; ny++){ | |||
var nl = input[ny].substring(j, nx + 1); | |||
if(!/^[+|].*[+|]$/.test(nl)) break; | |||
if(/^\+[+-]*\+$/.test(nl)) result++; | |||
} | |||
} | |||
} | |||
} | |||
return result; | |||
} | |||
@@ -0,0 +1,115 @@ | |||
import { count } from './rectangles'; | |||
describe('Rectangles', () => { | |||
test('no rows', () => { | |||
const expected = 0; | |||
const actual = count([]); | |||
expect(actual).toEqual(expected); | |||
}); | |||
xtest('no columns', () => { | |||
const expected = 0; | |||
const actual = count(['']); | |||
expect(actual).toEqual(expected); | |||
}); | |||
xtest('no rectangles', () => { | |||
const expected = 0; | |||
const actual = count([' ']); | |||
expect(actual).toEqual(expected); | |||
}); | |||
xtest('one rectangle', () => { | |||
const expected = 1; | |||
const actual = count(['+-+', '| |', '+-+']); | |||
expect(actual).toEqual(expected); | |||
}); | |||
xtest('two rectangles without shared parts', () => { | |||
const expected = 2; | |||
const actual = count([' +-+', ' | |', '+-+-+', '| | ', '+-+ ']); | |||
expect(actual).toEqual(expected); | |||
}); | |||
xtest('five rectangles with shared parts', () => { | |||
const expected = 5; | |||
const actual = count([' +-+', ' | |', '+-+-+', '| | |', '+-+-+']); | |||
expect(actual).toEqual(expected); | |||
}); | |||
xtest('rectangle of height 1 is counted', () => { | |||
const expected = 1; | |||
const actual = count(['+--+', '+--+']); | |||
expect(actual).toEqual(expected); | |||
}); | |||
xtest('rectangle of width 1 is counted', () => { | |||
const expected = 1; | |||
const actual = count(['++', '||', '++']); | |||
expect(actual).toEqual(expected); | |||
}); | |||
xtest('1x1 square is counted', () => { | |||
const expected = 1; | |||
const actual = count(['++', '++']); | |||
expect(actual).toEqual(expected); | |||
}); | |||
xtest('only complete rectangles are counted', () => { | |||
const expected = 1; | |||
const actual = count([' +-+', ' |', '+-+-+', '| | -', '+-+-+']); | |||
expect(actual).toEqual(expected); | |||
}); | |||
xtest('rectangles can be of different sizes', () => { | |||
const expected = 3; | |||
const actual = count([ | |||
'+------+----+', | |||
'| | |', | |||
'+---+--+ |', | |||
'| | |', | |||
'+---+-------+', | |||
]); | |||
expect(actual).toEqual(expected); | |||
}); | |||
xtest('corner is required for a rectangle to be complete', () => { | |||
const expected = 2; | |||
const actual = count([ | |||
'+------+----+', | |||
'| | |', | |||
'+------+ |', | |||
'| | |', | |||
'+---+-------+', | |||
]); | |||
expect(actual).toEqual(expected); | |||
}); | |||
xtest('large input with many rectangles', () => { | |||
const expected = 60; | |||
const actual = count([ | |||
'+---+--+----+', | |||
'| +--+----+', | |||
'+---+--+ |', | |||
'| +--+----+', | |||
'+---+--+--+-+', | |||
'+---+--+--+-+', | |||
'+------+ | |', | |||
' +-+', | |||
]); | |||
expect(actual).toEqual(expected); | |||
}); | |||
}); |