Tag, lint, build

This commit is contained in:
Angelos Chalaris
2017-12-14 23:29:12 +02:00
parent c666b27a8e
commit ec240463b5
2 changed files with 47 additions and 0 deletions

View File

@ -33,6 +33,7 @@
* [Initialize array with values](#initialize-array-with-values) * [Initialize array with values](#initialize-array-with-values)
* [Last of list](#last-of-list) * [Last of list](#last-of-list)
* [Median of array of numbers](#median-of-array-of-numbers) * [Median of array of numbers](#median-of-array-of-numbers)
* [Nth element of array](#nth-element-of-array)
* [Pick](#pick) * [Pick](#pick)
* [Shuffle array](#shuffle-array) * [Shuffle array](#shuffle-array)
* [Similarity between arrays](#similarity-between-arrays) * [Similarity between arrays](#similarity-between-arrays)
@ -71,6 +72,7 @@
* [Hamming distance](#hamming-distance) * [Hamming distance](#hamming-distance)
* [Percentile](#percentile) * [Percentile](#percentile)
* [Powerset](#powerset) * [Powerset](#powerset)
* [Round number to n digits](#round-number-to-n-digits)
* [Standard deviation](#standard-deviation) * [Standard deviation](#standard-deviation)
### Media ### Media
@ -79,6 +81,7 @@
### Object ### Object
* [Object from key value pairs](#object-from-key-value-pairs) * [Object from key value pairs](#object-from-key-value-pairs)
* [Object to key value pairs](#object-to-key-value-pairs) * [Object to key value pairs](#object-to-key-value-pairs)
* [Shallow clone object](#shallow-clone-object)
### String ### String
* [Anagrams of string (with duplicates)](#anagrams-of-string-with-duplicates) * [Anagrams of string (with duplicates)](#anagrams-of-string-with-duplicates)
@ -394,6 +397,20 @@ const median = arr => {
[⬆ back to top](#table-of-contents) [⬆ back to top](#table-of-contents)
### Nth element of array
Use `Array.slice()` to get an array containing the nth element at the first place.
If the index is out of bounds, return `[]`.
Omit the second argument, `n`, to get the first element of the array.
```js
const nth = (arr, n=0) => (n>0? arr.slice(n,n+1) : arr.slice(n))[0];
// nth(['a','b','c'],1) -> 'b'
// nth(['a','b','b']-2) -> 'a'
```
[⬆ back to top](#table-of-contents)
### Pick ### Pick
Use `Array.reduce()` to convert the filtered/picked keys back to a object with the corresponding key:value pair if the key exist in the obj. Use `Array.reduce()` to convert the filtered/picked keys back to a object with the corresponding key:value pair if the key exist in the obj.
@ -798,6 +815,18 @@ const powerset = arr =>
[⬆ back to top](#table-of-contents) [⬆ back to top](#table-of-contents)
### Round number to n digits
Use `Math.round()` and template literals to round the number to the specified number of digits.
Omit the second argument, `decimals` to round to an integer.
```js
const round = (n, decimals=0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);
// round(1.005, 2) -> 1.01
```
[⬆ back to top](#table-of-contents)
### Standard deviation ### Standard deviation
Use `Array.reduce()` to calculate the mean, variance and the sum of the variance of the values, the variance of the values, then Use `Array.reduce()` to calculate the mean, variance and the sum of the variance of the values, the variance of the values, then
@ -858,6 +887,21 @@ const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]);
// objectToPairs({a: 1, b: 2}) -> [['a',1],['b',2]]) // objectToPairs({a: 1, b: 2}) -> [['a',1],['b',2]])
``` ```
[⬆ back to top](#table-of-contents)
### Shallow clone object
Use the object `...spread` operator to spread the properties of the target object into the clone.
```js
const shallowClone = obj => ({ ...obj });
/*
const a = { x: true, y: 1 };
const b = shallowClone(a);
a === b -> false
*/
```
[⬆ back to top](#table-of-contents) [⬆ back to top](#table-of-contents)
## String ## String

View File

@ -49,6 +49,7 @@ is-symbol:utility
last-of-list:array last-of-list:array
measure-time-taken-by-function:utility measure-time-taken-by-function:utility
median-of-array-of-numbers:array median-of-array-of-numbers:array
nth-element-of-array:array
number-to-array-of-digits:utility number-to-array-of-digits:utility
object-from-key-value-pairs:object object-from-key-value-pairs:object
object-to-key-value-pairs:object object-to-key-value-pairs:object
@ -63,8 +64,10 @@ random-number-in-range:utility
redirect-to-URL:browser redirect-to-URL:browser
reverse-a-string:string reverse-a-string:string
RGB-to-hexadecimal:utility RGB-to-hexadecimal:utility
round-number-to-n-digits:math
run-promises-in-series:function run-promises-in-series:function
scroll-to-top:browser scroll-to-top:browser
shallow-clone-object:object
shuffle-array:array shuffle-array:array
similarity-between-arrays:array similarity-between-arrays:array
sleep:function sleep:function