How to find distance between items on array – javascript [closed]

You could slice the array for mapping the items with the delta of the same indices.

var array = [1000, 2000, 5000, 4000, 300, 0, 1250],
    result = array.slice(1).map((v, i) => array[i] - v);
    
console.log(result);

Leave a Comment