title: How to execute parallel-loop in typescript
body: <p>To calculate the distance between two points (latitude, longitude), implemented a function of haversine formula. To improve performance, I want to execute this for-loop in parallel. Please comment how to do that? </p>
  
  <pre><code>  for (var _i = 0; _i &lt; count; _i++) { 
              var _dummy: number = haversine(36.12, -86.67,
                data[_i].position.lat, data[_i].position.lng);
            }
  </code></pre>
  
  <p>A complete list of source code for reference.</p>
  
  <pre><code>//There are 6200 points in the JSON file
  import data from './json/test.json';
  
  let radians = function (degree: number) {
  
    // degrees to radians
    let rad: number = degree * Math.PI / 180;
  
    return rad;
  }
  
  const haversine = (lat1: number, lon1: number, lat2: number, lon2: number) =&gt; {
  
    let dlat, dlon, a, c, R: number;
  
    R = 6372.8; // km
    dlat = radians(lat2 - lat1);
    dlon = radians(lon2 - lon1);
    lat1 = radians(lat1);
    lat2 = radians(lat2);
    a = Math.sin(dlat / 2) * Math.sin(dlat / 2) + Math.sin(dlon / 2) * Math.sin(dlon / 2) * Math.cos(lat1) * Math.cos(lat2)
    c = 2 * Math.asin(Math.sqrt(a));
    return R * c;
  }
  
  let test = function () {
    const keys = Object.keys(data);
  
    let count: number = keys.length;
    for (var _i = 0; _i &lt; count; _i++) {
      var _dummy: number = haversine(
        36.12, -86.67, data[_i].position.lat, data[_i].position.lng);
    }
  
  }
  </code></pre>