Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/damianc/prod-sum

Getting a sum and a produkt.
https://github.com/damianc/prod-sum

Last synced: about 1 month ago
JSON representation

Getting a sum and a produkt.

Awesome Lists containing this project

README

        

# prod-sum

Getting a sum and a product.

- `Math.sum(numbers, mapper?)`
- `Math.prod(numbers, mapper?)`

```
Math.sum([1,2,3,4])
// 10

Math.prod([1,2,3,4])
// 24
```

```
// sum of squares

Math.sum([1,2,3,4], x => x**2)
// 1^2 + 2^2 + 3^2 + 4^2
// 30
```

```
function hypot(...args) {
return Math.sqrt(
Math.sum(args, x => x**2)
);
}

hypot(1,2,3,4)
// 5.47722558

Math.hypot(1,2,3,4)
// 5.47722558
```