diff --git a/katas/closed-circuit/closed-circuit.js b/katas/closed-circuit/closed-circuit.js new file mode 100644 index 0000000..997f723 --- /dev/null +++ b/katas/closed-circuit/closed-circuit.js @@ -0,0 +1,3 @@ +function isCircuitClosed (matrix) { + // YOUR SOLUTION GOES HERE +}; diff --git a/katas/closed-circuit/closed-circuit_test.js b/katas/closed-circuit/closed-circuit_test.js new file mode 100644 index 0000000..1f14d6b --- /dev/null +++ b/katas/closed-circuit/closed-circuit_test.js @@ -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); + }); +}); diff --git a/katas/closed-circuit/readme.md b/katas/closed-circuit/readme.md new file mode 100644 index 0000000..b22a5e4 --- /dev/null +++ b/katas/closed-circuit/readme.md @@ -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 +}; +```