Build README
This commit is contained in:
12
README.md
12
README.md
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user