title: how to create a subarray from main array based on condition
body: <p>example dataset:</p>
  <pre><code>gpsWayPoints: [
        {
          lat: '17.440693333333336',
          lng: '78.50628666666667',
          date_time: '2080-01-06T00:24:56.120Z',
          distance: 0,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.433263333333333',
          lng: '78.50689666666668',
          date_time: '2080-01-06T00:22:56.002Z',
          distance: 0.8287087733164237,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.429486666666666',
          lng: '78.50369333333333',
          date_time: '2080-01-06T00:21:56.002Z',
          distance: 0.5402256643040251,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.424088333333334',
          lng: '78.50179333333334',
          date_time: '2080-01-06T00:20:56.002Z',
          distance: 0.6332081303595034,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.42061',
          lng: '78.50057166666667',
          date_time: '2080-01-06T00:19:56.002Z',
          distance: 0.40791226654328755,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.417028333333334',
          lng: '78.49909166666666',
          date_time: '2080-01-06T00:18:56.570Z',
          distance: 0.42809971563899557,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.412568333333336',
          lng: '78.49762000000001',
          date_time: '2080-01-06T00:17:56.570Z',
          distance: 0.5199288051409745,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.411456666666666',
          lng: '78.49548333333334',
          date_time: '2080-01-06T00:16:56.570Z',
          distance: 0.25821039960267494,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.411389999999997',
          lng: '78.492005',
          date_time: '2080-01-06T00:15:56.570Z',
          distance: 0.36912578981907956,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.400935',
          lng: '78.52104166666666',
          date_time: '2080-01-06T00:14:56.491Z',
          distance: 3.292921334387653,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.412578333333332',
          lng: '78.49109666666666',
          date_time: '2080-01-06T00:14:55.996Z',
          distance: 3.4309029256875814,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.401901666666667',
          lng: '78.518555',
          date_time: '2080-01-06T00:12:56.491Z',
          distance: 3.1459984980635216,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.41284166666667',
          lng: '78.491005',
          date_time: '2080-01-06T00:13:55.996Z',
          distance: 3.166140088509945,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.409523333333333',
          lng: '78.49770333333332',
          date_time: '2080-01-06T00:12:56.526Z',
          distance: 0.8007709986297756,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.411695',
          lng: '78.49255333333333',
          date_time: '2080-01-06T00:12:55.996Z',
          distance: 2.965989837245471,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.40822166666667',
          lng: '78.49737499999999',
          date_time: '2080-01-06T00:11:56.691Z',
          distance: 0.6409999690505263,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.399521666666665',
          lng: '78.51642666666666',
          date_time: '2080-01-06T00:11:56.491Z',
          distance: 2.2410222983666306,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.411221666666666',
          lng: '78.49268333333333',
          date_time: '2080-01-06T00:11:56.077Z',
          distance: 2.8353452789417903,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.411440000000002',
          lng: '78.49550666666667',
          date_time: '2080-01-06T00:11:55.996Z',
          distance: 0.3005381432100544,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.411243333333335',
          lng: '78.49749833333334',
          date_time: '2080-01-06T00:10:56.834Z',
          distance: 0.21244455491246195,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.40613',
          lng: '78.49642999999999',
          date_time: '2080-01-06T00:10:56.691Z',
          distance: 0.5797655989840417,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.411546666666666',
          lng: '78.49614666666666',
          date_time: '2080-01-06T00:10:56.125Z',
          distance: 0.6030556113645753,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.39866',
          lng: '78.51431333333333',
          date_time: '2080-01-06T00:10:56.104Z',
          distance: 2.4018215106950453,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.407338333333332',
          lng: '78.49692499999999',
          date_time: '2080-01-06T00:09:56.834Z',
          distance: 2.0821095862034182,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.406011666666664',
          lng: '78.49841333333333',
          date_time: '2080-01-06T00:09:56.691Z',
          distance: 0.21610023320843036,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.43199333333333',
          lng: '78.36490666666667',
          date_time: '2080-01-06T00:09:56.373Z',
          distance: 14.456101590058049,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.410050000000002',
          lng: '78.49784166666667',
          date_time: '2080-01-06T00:09:56.125Z',
          distance: 14.313176158604973,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.398725000000002',
          lng: '78.51339666666667',
          date_time: '2080-01-06T00:09:56.104Z',
          distance: 2.076000291317401,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.459118333333333',
          lng: '78.36602833333333',
          date_time: '2080-01-06T00:09:22.560Z',
          distance: 17.015522281993626,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.406356666666667',
          lng: '78.49784833333334',
          date_time: '2080-01-06T00:08:56.834Z',
          distance: 15.165264249197879,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.404976666666666',
          lng: '78.50129',
          date_time: '2080-01-06T00:08:56.691Z',
          distance: 0.39610296742272316,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.423251949490044',
          lng: '78.33383428557552',
          date_time: '2080-01-06T00:07:56.281Z',
          distance: 17.88263411307325,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.40606',
          lng: '78.49624666666666',
          date_time: '2080-01-06T00:08:56.125Z',
          distance: 17.337370632596954,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.398766666666667',
          lng: '78.51336666666666',
          date_time: '2080-01-06T00:08:56.104Z',
          distance: 1.9893328088166493,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.456436666666665',
          lng: '78.36464666666667',
          date_time: '2080-01-06T00:08:22.560Z',
          distance: 17.031164826792647,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.404255',
          lng: '78.50350166666666',
          date_time: '2080-01-06T00:07:56.834Z',
          distance: 15.832540067875744,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.403796666666665',
          lng: '78.50447000000001',
          date_time: '2080-01-06T00:07:56.691Z',
          distance: 0.11468988982045415,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.412725000000002',
          lng: '78.49256166666667',
          date_time: '2080-01-06T00:07:56.419Z',
          distance: 1.606874783712649,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.406288333333336',
          lng: '78.49784833333334',
          date_time: '2080-01-06T00:07:56.125Z',
          distance: 17.503513276224655,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.453636666666668',
          lng: '78.36373166666667',
          date_time: '2080-01-06T00:07:22.560Z',
          distance: 17.006259128369884,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.403768333333336',
          lng: '78.50458499999999',
          date_time: '2080-01-06T00:06:56.753Z',
          distance: 15.938800423691951,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.411535',
          lng: '78.495995',
          date_time: '2080-01-06T00:06:56.738Z',
          distance: 1.2555923927334394,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.403881666666667',
          lng: '78.50440166666667',
          date_time: '2080-01-06T00:06:56.364Z',
          distance: 1.232811550158899,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
        {
          lat: '17.405745000000003',
          lng: '78.49933666666668',
          date_time: '2080-01-06T00:06:56.315Z',
          distance: 0.5759732633262876,
          temp: '0.0',
          target_temp: '-2684354.6',
          status: 'good',
          battery: '0'
        },
  ]
  </code></pre>
  <p>below is the logic Where i added a condition to check length of the array and split into subarrays each array has 100 values and I also want to a to calculate the distance value of object,if the sum of distance is greater then 200 i need to create sub arrays</p>
  <pre><code>for (var i = 0, parts = [], max = 100; i &lt; gpsWayPoints.length; i = i + max) {
      console.log(&quot;Math.min(i + max, gpsWayPoints.length)&quot;,Math.min(i + max, gpsWayPoints.length))
      const reducer = (accumulator, currentValue) =&gt; accumulator + currentValue;
      const distanceCal = gpsWayPoints.reduce(reducer)
      parts.push(gpsWayPoints.slice(i, Math.min(i + max, gpsWayPoints.length)));
  }
  console.log(&quot;2.parts&quot;,parts)
  </code></pre>
  <p>please can anyone help me out??</p>