or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

array.mdcollection.mddate.mdfunction.mdindex.mdlang.mdmath.mdnumber.mdobject.mdseq.mdstring.mdutil.md
tile.json

math.mddocs/

0

# Math Functions

1

2

Mathematical utilities for arithmetic operations, rounding, and statistical calculations.

3

4

## Capabilities

5

6

### Basic Arithmetic

7

8

```javascript { .api }

9

/**

10

* Adds two numbers

11

* @param {number} augend - The first number in an addition

12

* @param {number} addend - The second number in an addition

13

* @returns {number} Returns the total

14

*/

15

function add(augend, addend);

16

17

/**

18

* Subtracts two numbers

19

* @param {number} minuend - The first number in a subtraction

20

* @param {number} subtrahend - The second number in a subtraction

21

* @returns {number} Returns the difference

22

*/

23

function subtract(minuend, subtrahend);

24

25

/**

26

* Multiplies two numbers

27

* @param {number} multiplier - The first number in a multiplication

28

* @param {number} multiplicand - The second number in a multiplication

29

* @returns {number} Returns the product

30

*/

31

function multiply(multiplier, multiplicand);

32

33

/**

34

* Divides two numbers

35

* @param {number} dividend - The first number in a division

36

* @param {number} divisor - The second number in a division

37

* @returns {number} Returns the quotient

38

*/

39

function divide(dividend, divisor);

40

```

41

42

### Rounding and Precision

43

44

```javascript { .api }

45

/**

46

* Computes number rounded up to precision

47

* @param {number} number - The number to round up

48

* @param {number} precision - The precision to round up to

49

* @returns {number} Returns the rounded up number

50

*/

51

function ceil(number, precision);

52

53

/**

54

* Computes number rounded down to precision

55

* @param {number} number - The number to round down

56

* @param {number} precision - The precision to round down to

57

* @returns {number} Returns the rounded down number

58

*/

59

function floor(number, precision);

60

61

/**

62

* Computes number rounded to precision

63

* @param {number} number - The number to round

64

* @param {number} precision - The precision to round to

65

* @returns {number} Returns the rounded number

66

*/

67

function round(number, precision);

68

```

69

70

### Array Statistics

71

72

```javascript { .api }

73

/**

74

* Computes the maximum value of array

75

* @param {Array} array - The array to iterate over

76

* @returns {*} Returns the maximum value

77

*/

78

function max(array);

79

80

/**

81

* Like max but accepts iteratee for value comparison

82

* @param {Array} array - The array to iterate over

83

* @param {Function} iteratee - The iteratee invoked per element

84

* @returns {*} Returns the maximum value

85

*/

86

function maxBy(array, iteratee);

87

88

/**

89

* Computes the minimum value of array

90

* @param {Array} array - The array to iterate over

91

* @returns {*} Returns the minimum value

92

*/

93

function min(array);

94

95

/**

96

* Like min but accepts iteratee for value comparison

97

* @param {Array} array - The array to iterate over

98

* @param {Function} iteratee - The iteratee invoked per element

99

* @returns {*} Returns the minimum value

100

*/

101

function minBy(array, iteratee);

102

103

/**

104

* Computes the sum of the values in array

105

* @param {Array} array - The array to iterate over

106

* @returns {number} Returns the sum

107

*/

108

function sum(array);

109

110

/**

111

* Like sum but accepts iteratee for value selection

112

* @param {Array} array - The array to iterate over

113

* @param {Function} iteratee - The iteratee invoked per element

114

* @returns {number} Returns the sum

115

*/

116

function sumBy(array, iteratee);

117

118

/**

119

* Computes the mean of the values in array

120

* @param {Array} array - The array to iterate over

121

* @returns {number} Returns the mean

122

*/

123

function mean(array);

124

125

/**

126

* Like mean but accepts iteratee for value selection

127

* @param {Array} array - The array to iterate over

128

* @param {Function} iteratee - The iteratee invoked per element

129

* @returns {number} Returns the mean

130

*/

131

function meanBy(array, iteratee);

132

```

133

134

## Usage Examples

135

136

```javascript

137

import { add, subtract, multiply, divide, sum, mean, max, min } from "lodash-es";

138

139

// Basic arithmetic

140

console.log(add(6, 4)); // 10

141

console.log(subtract(10, 3)); // 7

142

console.log(multiply(3, 4)); // 12

143

console.log(divide(12, 3)); // 4

144

145

// Array operations

146

const scores = [85, 92, 78, 96, 88];

147

console.log(sum(scores)); // 439

148

console.log(mean(scores)); // 87.8

149

console.log(max(scores)); // 96

150

console.log(min(scores)); // 78

151

152

// With iteratees

153

const users = [

154

{ name: "Alice", score: 85 },

155

{ name: "Bob", score: 92 },

156

{ name: "Charlie", score: 78 }

157

];

158

159

console.log(sumBy(users, "score")); // 255

160

console.log(meanBy(users, "score")); // 85

161

console.log(maxBy(users, "score")); // { name: "Bob", score: 92 }

162

```