For the beginning we have two points with coordinates x, y, z: start(0, 0, 0) and randomly generated r(x, y, z) where x, y, z are random integers from 0 to 100.

There is a function (already written by me) that calculates distance between start point and r.

I need to write another function that takes only distance as an argument. We need to call the first function using different coordinates inside start point (to change distance between points) until we find the coordinates of r (that is distance should be equal to 0).

What is the best algorithm in this case?

My first part of the code including function that calculates distance:

```
const r = [];
for (let i = 0; i < 3; i++) {
    r.push(Math.floor(Math.random() * 100) + 1); // Generating random r point
}

const s = [0, 0, 0];
let distance;

function calculateDistance(random, myPoint) {
    distance = Math.abs(
                    Math.floor(
                        Math.sqrt(
                            Math.pow((random[0] - myPoint[0]), 2) +
                            Math.pow((random[1] - myPoint[1]), 2) + 
                            Math.pow((random[2] - myPoint[2]), 2)
                        )
                    )
                    );
    return distance;
}

```

Next I did the following:

```

function searchPoint(distance) {
    let min = 173,   // biggest possible distance if r(100, 100, 100)
        tempArr = [],
        closePoints = [],
        prev;

    for (let i = 0; i < s.length; i++) {
        while (s[i] < 100) {  // For x, y, z of start point I go through every possible value
            prev = min; // Keep track on previos min value                              
            if (min > distance) {
                min = distance;
            }

            if (prev < distance) { // If the distance increases it means we're drifting away from needed coordinates
                break;
            }

            tempArr.push({distance, point: s[i]});  // Here I save pairs distance-coordinate
            s[i]++;
            distance = calculateDistance(r, s);
        }
        closePoints.push(tempArr.filter(obj => obj.distance === min)); // For each of 3 coordinates I leave only minimal values, but the thing is there are several of them
        tempArr = [];
        min = 173;
    }

    let mappedPoints = closePoints.map(arr => {
        let mid = Math.floor((arr.length - 1) / 2); // So as a solution I try to pick up middle element from an array of points close to the needed one (which works most of the time BUT*)
        return arr[mid];
    });
    console.log(mappedPoints);
    mappedPoints.forEach((obj, i) => s[i] = obj.point); 

    console.log(s);
    console.log(calculateDistance(r, s));

    if (calculateDistance(r, s) === 0) {            // We check up on the distance and it's only logical that if it's equal to 0 - we found the point
        console.log('Point was found!!!');
    }

```

* But! In boundary values (let's say <14 and >86), the needed point in the closePoints array won't be IN THE MIDDLE (for example, 2/5/94/98)
In addition, there may be more than one such point - in cases like [3, 45, 93].
So this is the part where I got stuck...