Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find out whether the shape is a cube #2

Merged
merged 1 commit into from
Jan 31, 2024
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
18 changes: 18 additions & 0 deletions 8kyu/Find out whether the shape is a cube/README.md
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions 8kyu/Find out whether the shape is a cube/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function cubeChecker(volume, side) {
if (volume <= 0 || side <= 0) {
return false;
}

return volume === side ** 3;
}
14 changes: 14 additions & 0 deletions 8kyu/Find out whether the shape is a cube/task.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

2 changes: 1 addition & 1 deletion 8kyu/_example/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function sum(m, n) {
function example(m, n) {
return m + n;
}
6 changes: 3 additions & 3 deletions 8kyu/_example/task.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading