UNPKG

stringzy

Version:

A versatile string manipulation library providing a range of text utilities for JavaScript and Node.js applications.

32 lines (31 loc) 798 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isNegative = isNegative; exports.getOrderOfMagnitude = getOrderOfMagnitude; /** * Checks if a number is negative */ function isNegative(num) { return num < 0; } /** * Gets the highest order of magnitude for a number * @example getOrderOfMagnitude(1234) returns 1000 * @example getOrderOfMagnitude(567) returns 100 */ function getOrderOfMagnitude(num) { const absNum = Math.abs(num); if (absNum >= 1000000000000) return 1000000000000; if (absNum >= 1000000000) return 1000000000; if (absNum >= 1000000) return 1000000; if (absNum >= 1000) return 1000; if (absNum >= 100) return 100; if (absNum >= 10) return 10; return 1; }