diff --git a/8kyu/Find out whether the shape is a cube/README.md b/8kyu/Find out whether the shape is a cube/README.md new file mode 100644 index 0000000..03a8c9c --- /dev/null +++ b/8kyu/Find out whether the shape is a cube/README.md @@ -0,0 +1,18 @@ +## Find out whether the shape is a cube + +https://www.codewars.com/kata/58d248c7012397a81800005c + +To find the volume (centimeters cubed) of a cuboid you use the formula: + +`volume = Length * Width * Height` + +But someone forgot to use proper record keeping, so we only have the volume, and the length of a single side! + +It's up to you to find out whether the cuboid has equal sides (= is a cube). + +Return true if the cuboid could have equal sides, return false otherwise. + +Return false for invalid numbers too (e.g volume or side is less than or equal to 0). + +Note: side will be an integer + diff --git a/8kyu/Find out whether the shape is a cube/index.js b/8kyu/Find out whether the shape is a cube/index.js new file mode 100644 index 0000000..273cf0b --- /dev/null +++ b/8kyu/Find out whether the shape is a cube/index.js @@ -0,0 +1,7 @@ +function cubeChecker(volume, side) { + if (volume <= 0 || side <= 0) { + return false; + } + + return volume === side ** 3; +} diff --git a/8kyu/Find out whether the shape is a cube/task.test.js b/8kyu/Find out whether the shape is a cube/task.test.js new file mode 100644 index 0000000..260ecb8 --- /dev/null +++ b/8kyu/Find out whether the shape is a cube/task.test.js @@ -0,0 +1,14 @@ +describe('Tests', () => { + it('cubeChecker', () => { + expect(cubeChecker(56.3, 1)).toBe(false); + expect(cubeChecker(-1, 2)).toBe(false); + expect(cubeChecker(8, 3)).toBe(false); + expect(cubeChecker(8, 2)).toBe(true); + expect(cubeChecker(-8, -2)).toBe(false); + expect(cubeChecker(0, 0)).toBe(false); + expect(cubeChecker(1, 5)).toBe(false); + expect(cubeChecker(125, 5)).toBe(true); + expect(cubeChecker(125, -5)).toBe(false); + }); +}); + diff --git a/8kyu/_example/index.js b/8kyu/_example/index.js index e06a5bb..192afe3 100644 --- a/8kyu/_example/index.js +++ b/8kyu/_example/index.js @@ -1,3 +1,3 @@ -function sum(m, n) { +function example(m, n) { return m + n; } diff --git a/8kyu/_example/task.test.js b/8kyu/_example/task.test.js index ee321c1..5e9a02c 100644 --- a/8kyu/_example/task.test.js +++ b/8kyu/_example/task.test.js @@ -1,5 +1,5 @@ -describe('example test', () => { - it('1+1=2', () => { - expect(sum(1, 1)).toBe(2); +describe('Tests', () => { + it('example', () => { + expect(example(1, 1)).toBe(2); }); });