Build README

This commit is contained in:
Angelos Chalaris
2017-12-13 13:28:38 +02:00
parent 2575970786
commit f850cea25a

View File

@ -41,6 +41,7 @@
* [Measure time taken by function](#measure-time-taken-by-function)
* [Median of array of numbers](#median-of-array-of-numbers)
* [Object from key value pairs](#object-from-key-value-pairs)
* [Percentile](#percentile)
* [Pipe](#pipe)
* [Powerset](#powerset)
* [Random integer in range](#random-integer-in-range)
@ -411,6 +412,17 @@ const objectFromPairs = arr => arr.reduce((a,v) => (a[v[0]] = v[1], a), {});
// objectFromPairs([['a',1],['b',2]]) -> {a: 1, b: 2}
```
### Percentile
Use `Array.reduce()` to calculate how many numbers are below the value and how many are the same value and
apply the percentile formula.
```js
const percentile = (arr, val) =>
100 * arr.reduce((acc,v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0) / arr.length;
// percentile([1,2,3,4,5,6,7,8,9,10], 6) -> 55
```
### Pipe
Use `Array.reduce()` to pass value through functions.