mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 11:45:26 +03:00
cf65b2c601
* chore: add prettierrc * chore: apply format with prettier config * chore: eslint error fix
28 lines
472 B
Markdown
28 lines
472 B
Markdown
# sum
|
|
|
|
Calculates the sum of an array of numbers.
|
|
|
|
This function takes an array of numbers and returns the sum of all the elements in the array.
|
|
|
|
## Signature
|
|
|
|
```typescript
|
|
function sum(nums: number[]): number;
|
|
```
|
|
|
|
### Parameters
|
|
|
|
- `nums` (`number[]`): An array of numbers to be summed.
|
|
|
|
### Returns
|
|
|
|
(`number`): The sum of all the numbers in the array.
|
|
|
|
## Examples
|
|
|
|
```typescript
|
|
const numbers = [1, 2, 3, 4, 5];
|
|
const result = sum(numbers);
|
|
// result will be 15
|
|
```
|