Each day I solve several coding challenges and puzzles from Codr's ranked mode. The goal is to reach genius rank, along the way I explain how I solve them. You do not need any programming background to get started, and you will learn a ton of new and interesting things as you go.

We finally made it to the genius rank, this is the very first challenge on the highest rank. I hope you're as excited as I am. I will continue doing several more daily challenges.

```
function helper(p1, p2) {
const deltaX = p1[0] - p2[0];
const ðŸ’° = p1[1] - p2[1];
return ðŸš€ * deltaX + deltaY * deltaY;
}
function checker(p1, p2, p3, p4) {
const HP = [helper(p1, p2), helper(p1, p3), helper(p1, p4), helper(p2, p3), helper(p2, p4), helper(p3, p4)];
let cnt1 = 0;
let cnt2 = 0;
let sum = 0;
for (let i = 0; i < HP.length; i++) {
sum += HP[i];
}
for (let i = 0; i < HP.length; i++) {
if (sum === 8 * HP[ðŸ’š]) {
cnt1++;
} else if (sum === 4 * HP[ðŸ’Ž]) {
cnt2++;
}
}
return cnt1 === 4 && cnt2 === 2;
}
let p1 = [6, 9], p2 = [3, 1];
let p3 = [7, 0], p4 = [3, 7];
let A = checker(p1, p2, p3, p4);
// ðŸ’° = ? (identifier)
// ðŸ’š = ? (identifier)
// ðŸ’Ž = ? (identifier)
// ðŸš€ = ? (identifier)
// such that A = false (boolean)
```

In this challenge we need to fix four bugs, after a quick look at the code it should be an easy procedure.

The first two bugs appear within the same short function `helper`

:

```
function helper(p1, p2) {
const deltaX = p1[0] - p2[0];
const ðŸ’° = p1[1] - p2[1];
return ðŸš€ * deltaX + deltaY * deltaY;
}
```

The variable declaration for ðŸ’° should be `deltaY`

, and ðŸš€ is very likely to be `deltaX`

because the function seems to be computing `dxÂ² + dyÂ²`

.

The final two bugs appear here:

```
for (let i = 0; i < HP.length; i++) {
if (sum === 8 * HP[ðŸ’š]) {
cnt1++;
} else if (sum === 4 * HP[ðŸ’Ž]) {
cnt2++;
}
}
```

Both these bugs are indices for the array `HP`

. Since both are within a for-loop whose `i`

variable isn't used, it seems very likely that both bugs should be `i`

.

All our assumptions were correct! We are likely to encounter this function again in the near future, so for now we skip its detailed analysis.

By solving these challenges you train yourself to be a better programmer. You'll learn newer and better ways of analyzing, debugging and improving code. As a result you'll be more productive and valuable in business. Get started and become a certified Codr today at https://nevolin.be/codr/

## Top comments (0)