Utilities
sign

sign

Returns the sign of a number. The sign of a number indicates whether the number is positive, negative or zero.

Installation

npm install @madeinhaus/utils

Import

import { sign } from '@madeinhaus/utils';

Parameters

  • n (number): The number to get the sign of.

Returns

  • (number): 1 if the number is positive or 0, -1 if the number is negative.

Usage

import { sign } from '@madeinhaus/utils';
 
const n1 = 10;
const n2 = -10;
const n3 = 0;
const sign1 = sign(n1); // 1
const sign2 = sign(n2); // -1
const sign3 = sign(n3); // 1

In this example, we import the sign function from the @madeinhaus/utils package and use it to get the sign of three numbers.