src/lib/metrics.js
// merge two sorted set of data
merge two sorted set of data
merge two sorted set of data
function mergeWith(merge, d1, d2) {
  const l1 = d1.length;
  const l2 = d2.length;
  let c1 = 0;
  let c2 = 0;
  const result = [];
  while (c1 < l1 || c2 < l2) {
    if (c1 === l1) {
      result.push(...d2.slice(c2));
      return result;
    }
    if (c2 === l2) {
      result.push(...d1.slice(c1));
      return result;
    }
    if (d1[c1][0] === d2[c2][0]) {
      result.push([d1[c1][0], merge(d1[c1][1], d2[c2][1])]);
      c1++;
      c2++;
    } else if (d1[c1][0] < d2[c2][0]) {
      result.push(d1[c1]);
      c1++;
    } else {
      result.push(d2[c2]);
      c2++;
    }
  }
  return result;
}
function mergeWith ( merge , d1 , d2 ) { const l1 = d1 . length ; const l2 = d2 . length ; let c1 = 0 ; let c2 = 0 ; const result = [ ] ; while ( c1 < l1 || c2 < l2 ) { if ( c1 === l1 ) { result . push ( ... d2 . slice ( c2 ) ) ; return result ; } if ( c2 === l2 ) { result . push ( ... d1 . slice ( c1 ) ) ; return result ; } if ( d1 [ c1 ] [ 0 ] === d2 [ c2 ] [ 0 ] ) { result . push ( [ d1 [ c1 ] [ 0 ] , merge ( d1 [ c1 ] [ 1 ] , d2 [ c2 ] [ 1 ] ) ] ) ; c1 ++ ; c2 ++ ; } else if ( d1 [ c1 ] [ 0 ] < d2 [ c2 ] [ 0 ] ) { result . push ( d1 [ c1 ] ) ; c1 ++ ; } else { result . push ( d2 [ c2 ] ) ; c2 ++ ; } } return result ; }
merge two sorted set of data
merge two sorted set of data