npm-lodash

Description
A comprehensive JavaScript utility library with 296+ functions for arrays, objects, strings, and functional programming
Author
tessl
Last updated

How to use

npx @tessl/cli registry install tessl/npm-lodash@4.9.0

math-methods.md docs/

1
# Math Methods
2
3
Mathematical computations including basic arithmetic, aggregation functions, and range utilities for numerical operations.
4
5
## Capabilities
6
7
### Add
8
9
Adds two numbers.
10
11
```javascript { .api }
12
/**
13
* Adds two numbers.
14
* @param augend - The first number in an addition
15
* @param addend - The second number in an addition
16
* @returns Returns the sum
17
*/
18
function add(augend: number, addend: number): number;
19
```
20
21
### Ceil
22
23
Computes number rounded up to precision.
24
25
```javascript { .api }
26
/**
27
* Computes `number` rounded up to `precision`.
28
* @param number - The number to round up
29
* @param precision - The precision to round up to (defaults to 0)
30
* @returns Returns the rounded up number
31
*/
32
function ceil(number: number, precision?: number): number;
33
```
34
35
### Divide
36
37
Divide two numbers.
38
39
```javascript { .api }
40
/**
41
* Divide two numbers.
42
* @param dividend - The first number in a division
43
* @param divisor - The second number in a division
44
* @returns Returns the quotient
45
*/
46
function divide(dividend: number, divisor: number): number;
47
```
48
49
### Floor
50
51
Computes number rounded down to precision.
52
53
```javascript { .api }
54
/**
55
* Computes `number` rounded down to `precision`.
56
* @param number - The number to round down
57
* @param precision - The precision to round down to (defaults to 0)
58
* @returns Returns the rounded down number
59
*/
60
function floor(number: number, precision?: number): number;
61
```
62
63
### Max
64
65
Computes the maximum value of array.
66
67
```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 over
72
* @returns Returns the maximum value
73
*/
74
function max<T>(array: T[]): T | undefined;
75
```
76
77
### Max By
78
79
Like max except that it accepts iteratee which is invoked for each element to generate the criterion by which the value is ranked.
80
81
```javascript { .api }
82
/**
83
* This method is like `max` except that it accepts `iteratee` which is
84
* invoked for each element in `array` to generate the criterion by which
85
* the value is ranked. The iteratee is invoked with one argument: (value).
86
* @param array - The array to iterate over
87
* @param iteratee - The iteratee invoked per element
88
* @returns Returns the maximum value
89
*/
90
function maxBy<T>(
91
array: T[],
92
iteratee?: string | ((value: T) => any)
93
): T | undefined;
94
```
95
96
### Mean
97
98
Computes the mean of the values in array.
99
100
```javascript { .api }
101
/**
102
* Computes the mean of the values in `array`.
103
* @param array - The array to iterate over
104
* @returns Returns the mean
105
*/
106
function mean(array: number[]): number;
107
```
108
109
### Mean By
110
111
Like mean except that it accepts iteratee which is invoked for each element to generate the value to be averaged.
112
113
```javascript { .api }
114
/**
115
* This method is like `mean` except that it accepts `iteratee` which is
116
* 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 over
119
* @param iteratee - The iteratee invoked per element
120
* @returns Returns the mean
121
*/
122
function meanBy<T>(
123
array: T[],
124
iteratee?: string | ((value: T) => number)
125
): number;
126
```
127
128
### Min
129
130
Computes the minimum value of array.
131
132
```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 over
137
* @returns Returns the minimum value
138
*/
139
function min<T>(array: T[]): T | undefined;
140
```
141
142
### Min By
143
144
Like min except that it accepts iteratee which is invoked for each element to generate the criterion by which the value is ranked.
145
146
```javascript { .api }
147
/**
148
* This method is like `min` except that it accepts `iteratee` which is
149
* invoked for each element in `array` to generate the criterion by which
150
* the value is ranked. The iteratee is invoked with one argument: (value).
151
* @param array - The array to iterate over
152
* @param iteratee - The iteratee invoked per element
153
* @returns Returns the minimum value
154
*/
155
function minBy<T>(
156
array: T[],
157
iteratee?: string | ((value: T) => any)
158
): T | undefined;
159
```
160
161
### Multiply
162
163
Multiply two numbers.
164
165
```javascript { .api }
166
/**
167
* Multiply two numbers.
168
* @param multiplier - The first number in a multiplication
169
* @param multiplicand - The second number in a multiplication
170
* @returns Returns the product
171
*/
172
function multiply(multiplier: number, multiplicand: number): number;
173
```
174
175
### Round
176
177
Computes number rounded to precision.
178
179
```javascript { .api }
180
/**
181
* Computes `number` rounded to `precision`.
182
* @param number - The number to round
183
* @param precision - The precision to round to (defaults to 0)
184
* @returns Returns the rounded number
185
*/
186
function round(number: number, precision?: number): number;
187
```
188
189
### Subtract
190
191
Subtract two numbers.
192
193
```javascript { .api }
194
/**
195
* Subtract two numbers.
196
* @param minuend - The first number in a subtraction
197
* @param subtrahend - The second number in a subtraction
198
* @returns Returns the difference
199
*/
200
function subtract(minuend: number, subtrahend: number): number;
201
```
202
203
### Sum
204
205
Computes the sum of the values in array.
206
207
```javascript { .api }
208
/**
209
* Computes the sum of the values in `array`.
210
* @param array - The array to iterate over
211
* @returns Returns the sum
212
*/
213
function sum(array: number[]): number;
214
```
215
216
### Sum By
217
218
Like sum except that it accepts iteratee which is invoked for each element to generate the value to be summed.
219
220
```javascript { .api }
221
/**
222
* This method is like `sum` except that it accepts `iteratee` which is
223
* 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 over
226
* @param iteratee - The iteratee invoked per element
227
* @returns Returns the sum
228
*/
229
function sumBy<T>(
230
array: T[],
231
iteratee?: string | ((value: T) => number)
232
): number;
233
```
234
235
## Range Methods
236
237
### In Range
238
239
Checks if n is between start and up to, but not including, end.
240
241
```javascript { .api }
242
/**
243
* Checks if `n` is between `start` and up to, but not including, `end`. If
244
* `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 support
246
* negative ranges.
247
* @param number - The number to check
248
* @param start - The start of the range
249
* @param end - The end of the range
250
* @returns Returns `true` if `number` is in the range, else `false`
251
*/
252
function inRange(number: number, start: number, end?: number): boolean;
253
```
254
255
### Range
256
257
Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end.
258
259
```javascript { .api }
260
/**
261
* Creates an array of numbers (positive and/or negative) progressing from
262
* `start` up to, but not including, `end`. A step of `-1` is used if a negative
263
* `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 range
266
* @param end - The end of the range
267
* @param step - The value to increment or decrement by (defaults to 1)
268
* @returns Returns the range of numbers
269
*/
270
function range(start?: number, end?: number, step?: number): number[];
271
```
272
273
### Range Right
274
275
Like range except that it populates values in descending order.
276
277
```javascript { .api }
278
/**
279
* This method is like `range` except that it populates values in
280
* descending order.
281
* @param start - The start of the range
282
* @param end - The end of the range
283
* @param step - The value to increment or decrement by (defaults to 1)
284
* @returns Returns the range of numbers
285
*/
286
function rangeRight(start?: number, end?: number, step?: number): number[];
287
```