All files / number/src equalSign.ts

100% Statements 4/4
100% Branches 1/1
100% Functions 3/3
100% Lines 4/4

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 21 22 23                                  8x 1x 8x 8x    
/**
 * Checks if two numbers have equal signs.
 *
 * `+0` and `-0` are considered equal.
 *
 * @example
 * ```ts
 * const result = equalSign(3, 0.5);
 *
 * console.log(result); // true
 * ```
 *
 * @param numberA - the number to compare against
 * @returns `true` if both numbers have the same sign, otherwise `false`
 */
type EqualSign = (numberA: number) => (numberB: number) => boolean;
 
export const equalSign: EqualSign =
  (numberA: number, sign = Math.sign) =>
  (numberB: number): boolean => {
    return sign(numberA) == sign(numberB);
  };