I'm using the following code to get the distance of two xyz coordinates.

```
function dist(x0,y0,z0,x1,y1,z1){
  deltaX = x1 - x0;
  deltaY = y1 - y0;
  deltaZ = z1 - z0;
  distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
  return distance;
}

```

For given two coordinates.

```
arr1 = [1524519105.309092, 575131.076859, 4141688.619666, -14.086608]
arr2 = [1524519105.310092, 575131.082497, 4141688.628375, -14.086852]

```

Where index 0 represents timestamp; and following 3 numbers represent xyz.
My goal is to compare these 2 coordinates and derive speed. Here's what I have so far:

```
let x2 = arr2[1] // Array 2 x
let y2 = arr2[2] // Array 2 y
let z2 = arr2[3] // Array 2 z
let x1 = arr1[1] // Array 1 x
let y1 = arr1[2] // Array 1 y
let z1 = arr1[3] // Array 1 z
var c = dist(x1,y1,z1,x2,y2,z2)
var time_difference = arr1[0] - arr2[0] // time difference 
var speed = Math.round(c / time_difference);

```

The does not give me the right speed; there are times I get -0, which makes me believe I'm doing something wrong in time difference.
My overall goal is to get speed in meters per second.