All files / array/operator compareWith.ts

100% Statements 13/13
100% Branches 4/4
100% Functions 3/3
100% Lines 11/11

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    1x 4x 13x 13x 13x 6x   7x 42x 42x 5x     2x      
import {Comparer} from 'fnxt/fnxt-types';
 
export const compareWith = <T>(comparer: Comparer<T>) =>
  (a: T[]) =>
    (b: T[]) => {
      const length = a.length - b.length;
      if (length !== 0) {
        return length;
      }
      for (let i = 0; i < a.length; i++) {
        const cmp = comparer(a[i], b[i]);
        if (cmp !== 0) {
          return cmp;
        }
      }
      return 0;
 
    };