Skip to content

Commit d3d69fe

Browse files
committed
Added cats-and-mouse problem solution
1 parent 6e2950a commit d3d69fe

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Cats and a Mouse/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env node
2+
3+
// Problem Description at -> https://www.hackerrank.com/challenges/cats-and-a-mouse/problem
4+
5+
function catAndMouse(x, y, z) {
6+
if (Math.abs(z - x) == Math.abs(z - y)) return 'Mouse C';
7+
if (Math.abs(z - x) < Math.abs(z - y)) return 'Cat A';
8+
return 'Cat B';
9+
}
10+
11+
// console.log(catAndMouse(1, 2, 3)); // Cat B
12+
console.log(catAndMouse(1, 3, 2)); // Mouse C

0 commit comments

Comments
 (0)