All files / utils arrayUtils.ts

60% Statements 6/10
50% Branches 2/4
50% Functions 2/4
60% Lines 6/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20        3x 2x 2x 3x   2x     3x              
/*!
 * Copyright 2020 Cognite AS
 */
 
export function createOffsets(array: Float64Array): Float64Array {
  const offsets = new Float64Array(array.length);
  array.forEach((_, idx) => {
    offsets[idx] = idx > 0 ? offsets[idx - 1] + array[idx - 1] : 0;
  });
  return offsets;
}
 
export function createOffsetsArray(array: number[]): number[] {
  const offsets = new Array<number>(array.length);
  array.forEach((_, idx) => {
    offsets[idx] = idx > 0 ? offsets[idx - 1] + array[idx - 1] : 0;
  });
  return offsets;
}