Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions katas/closed-circuit/closed-circuit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function isCircuitClosed (matrix) {
// YOUR SOLUTION GOES HERE
};
24 changes: 24 additions & 0 deletions katas/closed-circuit/closed-circuit_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
describe('isCircuitClosed function', function() {
let area = [[0,0,0,1,1,0,0,0],
[0,0,0,1,0,1,0,0],
[0,0,0,1,0,1,0,0],
[0,0,0,0,0,0,0,0]];

it('should return false if circuit is\'nt closed', function() {
expect(isCircuitClosed(area)).toBe(false);
});

it('should return true if circuit closed', function() {
area[2][4] = 1;

expect(isCircuitClosed(area)).toBe(true);
});

it('should return false if only one link in circuit', function() {
area = [[0,0,0],
[0,1,0],
[0,0,0]];

expect(isCircuitClosed(area)).toBe(false);
});
});
33 changes: 33 additions & 0 deletions katas/closed-circuit/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Task
Create a function that check closed or nor circuit in provided 'area'.
Provided 'area' - Martix (n*m) that must contain only 0 and 1 (0 - empty, 1 - circuit link).
Links(1) can connect diagonally (45 degrees).

## Important note
Сircuit will be closed if circuit links form a closed area.
One circuit link(1) isn't closed circuit!

## Example

```js
let area = [[0,0,0,1,1,0,0,0],
[0,0,0,1,0,1,0,0],
[0,0,0,1,0,1,0,0],
[0,0,0,0,0,0,0,0]];

isCircuitClosed(area); // false
area[2][4] = 1
isCircuitClosed(area); // true
```

## Arguments
! Only matrix (n*m) !

See tests in [closed-circuit_test.js](https://github.com/AlexVvx/code-wars/blob/master/katas/closed-circuit/closed-circuit_test.js)

## Boilerplate
```js
function isCircuitClosed (matrix) {
// YOUR SOLUTION GOES HERE
};
```
You are viewing a condensed version of this merge commit. You can view the full changes here.