- Spec files
npm-lodash
Describes: pkg:npm/lodash@4.9.x
- Description
- A comprehensive JavaScript utility library with 296+ functions for arrays, objects, strings, and functional programming
- Author
- tessl
- Last updated
math-methods.md docs/
1# Math Methods23Mathematical computations including basic arithmetic, aggregation functions, and range utilities for numerical operations.45## Capabilities67### Add89Adds two numbers.1011```javascript { .api }12/**13* Adds two numbers.14* @param augend - The first number in an addition15* @param addend - The second number in an addition16* @returns Returns the sum17*/18function add(augend: number, addend: number): number;19```2021### Ceil2223Computes number rounded up to precision.2425```javascript { .api }26/**27* Computes `number` rounded up to `precision`.28* @param number - The number to round up29* @param precision - The precision to round up to (defaults to 0)30* @returns Returns the rounded up number31*/32function ceil(number: number, precision?: number): number;33```3435### Divide3637Divide two numbers.3839```javascript { .api }40/**41* Divide two numbers.42* @param dividend - The first number in a division43* @param divisor - The second number in a division44* @returns Returns the quotient45*/46function divide(dividend: number, divisor: number): number;47```4849### Floor5051Computes number rounded down to precision.5253```javascript { .api }54/**55* Computes `number` rounded down to `precision`.56* @param number - The number to round down57* @param precision - The precision to round down to (defaults to 0)58* @returns Returns the rounded down number59*/60function floor(number: number, precision?: number): number;61```6263### Max6465Computes the maximum value of array.6667```javascript { .api }68/**69* Computes the maximum value of `array`. If `array` is empty or falsey,70* `undefined` is returned.71* @param array - The array to iterate over72* @returns Returns the maximum value73*/74function max<T>(array: T[]): T | undefined;75```7677### Max By7879Like max except that it accepts iteratee which is invoked for each element to generate the criterion by which the value is ranked.8081```javascript { .api }82/**83* This method is like `max` except that it accepts `iteratee` which is84* invoked for each element in `array` to generate the criterion by which85* the value is ranked. The iteratee is invoked with one argument: (value).86* @param array - The array to iterate over87* @param iteratee - The iteratee invoked per element88* @returns Returns the maximum value89*/90function maxBy<T>(91array: T[],92iteratee?: string | ((value: T) => any)93): T | undefined;94```9596### Mean9798Computes the mean of the values in array.99100```javascript { .api }101/**102* Computes the mean of the values in `array`.103* @param array - The array to iterate over104* @returns Returns the mean105*/106function mean(array: number[]): number;107```108109### Mean By110111Like mean except that it accepts iteratee which is invoked for each element to generate the value to be averaged.112113```javascript { .api }114/**115* This method is like `mean` except that it accepts `iteratee` which is116* invoked for each element in `array` to generate the value to be averaged.117* The iteratee is invoked with one argument: (value).118* @param array - The array to iterate over119* @param iteratee - The iteratee invoked per element120* @returns Returns the mean121*/122function meanBy<T>(123array: T[],124iteratee?: string | ((value: T) => number)125): number;126```127128### Min129130Computes the minimum value of array.131132```javascript { .api }133/**134* Computes the minimum value of `array`. If `array` is empty or falsey,135* `undefined` is returned.136* @param array - The array to iterate over137* @returns Returns the minimum value138*/139function min<T>(array: T[]): T | undefined;140```141142### Min By143144Like min except that it accepts iteratee which is invoked for each element to generate the criterion by which the value is ranked.145146```javascript { .api }147/**148* This method is like `min` except that it accepts `iteratee` which is149* invoked for each element in `array` to generate the criterion by which150* the value is ranked. The iteratee is invoked with one argument: (value).151* @param array - The array to iterate over152* @param iteratee - The iteratee invoked per element153* @returns Returns the minimum value154*/155function minBy<T>(156array: T[],157iteratee?: string | ((value: T) => any)158): T | undefined;159```160161### Multiply162163Multiply two numbers.164165```javascript { .api }166/**167* Multiply two numbers.168* @param multiplier - The first number in a multiplication169* @param multiplicand - The second number in a multiplication170* @returns Returns the product171*/172function multiply(multiplier: number, multiplicand: number): number;173```174175### Round176177Computes number rounded to precision.178179```javascript { .api }180/**181* Computes `number` rounded to `precision`.182* @param number - The number to round183* @param precision - The precision to round to (defaults to 0)184* @returns Returns the rounded number185*/186function round(number: number, precision?: number): number;187```188189### Subtract190191Subtract two numbers.192193```javascript { .api }194/**195* Subtract two numbers.196* @param minuend - The first number in a subtraction197* @param subtrahend - The second number in a subtraction198* @returns Returns the difference199*/200function subtract(minuend: number, subtrahend: number): number;201```202203### Sum204205Computes the sum of the values in array.206207```javascript { .api }208/**209* Computes the sum of the values in `array`.210* @param array - The array to iterate over211* @returns Returns the sum212*/213function sum(array: number[]): number;214```215216### Sum By217218Like sum except that it accepts iteratee which is invoked for each element to generate the value to be summed.219220```javascript { .api }221/**222* This method is like `sum` except that it accepts `iteratee` which is223* invoked for each element in `array` to generate the value to be summed.224* The iteratee is invoked with one argument: (value).225* @param array - The array to iterate over226* @param iteratee - The iteratee invoked per element227* @returns Returns the sum228*/229function sumBy<T>(230array: T[],231iteratee?: string | ((value: T) => number)232): number;233```234235## Range Methods236237### In Range238239Checks if n is between start and up to, but not including, end.240241```javascript { .api }242/**243* Checks if `n` is between `start` and up to, but not including, `end`. If244* `end` is not specified, it's set to `start` with `start` then set to `0`.245* If `start` is greater than `end` the params are swapped to support246* negative ranges.247* @param number - The number to check248* @param start - The start of the range249* @param end - The end of the range250* @returns Returns `true` if `number` is in the range, else `false`251*/252function inRange(number: number, start: number, end?: number): boolean;253```254255### Range256257Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end.258259```javascript { .api }260/**261* Creates an array of numbers (positive and/or negative) progressing from262* `start` up to, but not including, `end`. A step of `-1` is used if a negative263* `start` is specified without an `end` or `step`. If `end` is not specified,264* it's set to `start` with `start` then set to `0`.265* @param start - The start of the range266* @param end - The end of the range267* @param step - The value to increment or decrement by (defaults to 1)268* @returns Returns the range of numbers269*/270function range(start?: number, end?: number, step?: number): number[];271```272273### Range Right274275Like range except that it populates values in descending order.276277```javascript { .api }278/**279* This method is like `range` except that it populates values in280* descending order.281* @param start - The start of the range282* @param end - The end of the range283* @param step - The value to increment or decrement by (defaults to 1)284* @returns Returns the range of numbers285*/286function rangeRight(start?: number, end?: number, step?: number): number[];287```