Tag, lint, build

This commit is contained in:
Angelos Chalaris
2017-12-17 11:52:35 +02:00
parent 1dea0ab2ea
commit 2519afd0ea
3 changed files with 47 additions and 12 deletions

View File

@ -12,6 +12,7 @@
### Array ### Array
* [Array difference](#array-difference) * [Array difference](#array-difference)
* [Array intersection](#array-intersection) * [Array intersection](#array-intersection)
* [Array pull (mutates array)](#array-pull-mutates-array)
* [Array remove](#array-remove) * [Array remove](#array-remove)
* [Array sample](#array-sample) * [Array sample](#array-sample)
* [Array symmetric difference](#array-symmetric-difference) * [Array symmetric difference](#array-symmetric-difference)
@ -79,6 +80,7 @@
* [Fibonacci array generator](#fibonacci-array-generator) * [Fibonacci array generator](#fibonacci-array-generator)
* [Greatest common divisor (GCD)](#greatest-common-divisor-gcd) * [Greatest common divisor (GCD)](#greatest-common-divisor-gcd)
* [Hamming distance](#hamming-distance) * [Hamming distance](#hamming-distance)
* [Least common multiple (LCM)](#least-common-multiple-lcm)
* [Percentile](#percentile) * [Percentile](#percentile)
* [Powerset](#powerset) * [Powerset](#powerset)
* [Random integer in range](#random-integer-in-range) * [Random integer in range](#random-integer-in-range)
@ -154,6 +156,23 @@ const intersection = (a, b) => { const s = new Set(b); return a.filter(x => s.ha
[⬆ back to top](#table-of-contents) [⬆ back to top](#table-of-contents)
### Array pull (mutates array)
Use `Array.filter()` and `Array.includes()` to pull out the values that are not needed.
Use `Array.length = 0` to mutate the passed in array by resetting it's length to zero and `Array.push()` to re-populate it with only the pulled values.
```js
const pull = (arr, ...args) => {
let pulled = arr.filter((v, i) => args.includes(v));
arr.length = 0; pulled.forEach(v => arr.push(v));
};
// let myArray = ['a', 'b', 'c', 'a', 'b', 'c'];
// pull(myArray, 'a', 'c');
// console.log(myArray) -> [ 'b', 'b' ]
```
[⬆ back to top](#table-of-contents)
### Array remove ### Array remove
Use `Array.filter()` to find array elements that return truthy values and `Array.reduce()` to remove elements using `Array.splice()`. Use `Array.filter()` to find array elements that return truthy values and `Array.reduce()` to remove elements using `Array.splice()`.
@ -450,10 +469,10 @@ const initializeArray = (n, value = 0) => Array(n).fill(value);
### Last of list ### Last of list
Use `arr.slice(-1)[0]` to get the last element of the given array. Use `arr.length - 1` to compute index of the last element of the given array and returning it.
```js ```js
const last = arr => arr.slice(-1)[0]; const last = arr => arr[arr.length - 1];
// last([1,2,3]) -> 3 // last([1,2,3]) -> 3
``` ```
@ -742,6 +761,7 @@ const multiplyAndAdd5 = compose(add5, multiply)
multiplyAndAdd5(5, 2) -> 15 multiplyAndAdd5(5, 2) -> 15
*/ */
``` ```
[⬆ back to top](#table-of-contents) [⬆ back to top](#table-of-contents)
### Curry ### Curry
@ -941,6 +961,21 @@ const hammingDistance = (num1, num2) =>
[⬆ back to top](#table-of-contents) [⬆ back to top](#table-of-contents)
### Least common multiple (LCM)
Use the greatest common divisor (GCD) formula and `Math.abs()` to determine the least common multiple.
The GCD formula uses recursion.
```js
const lcm = (x,y) => {
const gcd = (x, y) => !y ? x : gcd(y, x % y);
return Math.abs(x*y)/(gcd(x,y));
};
// lcm(12,7) -> 84
```
[⬆ back to top](#table-of-contents)
### Percentile ### Percentile
Use `Array.reduce()` to calculate how many numbers are below the value and how many are the same value and Use `Array.reduce()` to calculate how many numbers are below the value and how many are the same value and
@ -1266,12 +1301,11 @@ const truncate = (str, num) =>
### 3-digit hexcode to 6-digit hexcode ### 3-digit hexcode to 6-digit hexcode
Use `Array.map()`, `split()` and `Array.join()` to join the mapped array for converting a three-digit RGB notated hexadecimal colorcode to the six-digit form. Use `Array.map()`, `split()` and `Array.join()` to join the mapped array for converting a three-digit RGB notated hexadecimal color-code to the six-digit form.
`Array.slice()` is used to remove `#` from string start since it's added once.
```js ```js
const convertHex = shortHex => const convertHex = shortHex =>
shortHex[0] == '#' ? ('#' + shortHex.slice(1).split('').map(x => x+x).join('')) : '#' + shortHex.slice(shortHex.startsWith('#') ? 1 : 0).split().map(x => x+x).join()
('#' + shortHex.split('').map(x => x+x).join(''));
// convertHex('#03f') -> '#0033ff' // convertHex('#03f') -> '#0033ff'
// convertHex('05a') -> '#0055aa' // convertHex('05a') -> '#0055aa'
``` ```
@ -1403,11 +1437,11 @@ const timeTaken = callback => {
### Number to array of digits ### Number to array of digits
Convert the number to a string, use `split()` to convert build an array. Convert the number to a string, using spread operators in ES6(`[...string]`) build an array.
Use `Array.map()` and `parseInt()` to transform each value to an integer. Use `Array.map()` and `parseInt()` to transform each value to an integer.
```js ```js
const digitize = n => (''+n).split('').map(i => parseInt(i)); const digitize = n => [...''+n].map(i => parseInt(i));
// digitize(2334) -> [2, 3, 3, 4] // digitize(2334) -> [2, 3, 3, 4]
``` ```

View File

@ -11,4 +11,4 @@ const multiply = (x, y) => x * y
const multiplyAndAdd5 = compose(add5, multiply) const multiplyAndAdd5 = compose(add5, multiply)
multiplyAndAdd5(5, 2) -> 15 multiplyAndAdd5(5, 2) -> 15
*/ */
``` ```

View File

@ -2,6 +2,7 @@
anagrams-of-string-(with-duplicates):string anagrams-of-string-(with-duplicates):string
array-difference:array array-difference:array
array-intersection:array array-intersection:array
array-pull-(mutates-array):array
array-remove:array array-remove:array
array-sample:array array-sample:array
array-symmetric-difference:array array-symmetric-difference:array
@ -56,8 +57,9 @@ is-function:utility
is-number:utility is-number:utility
is-string:utility is-string:utility
is-symbol:utility is-symbol:utility
json-to-date: JSON-to-date:date
last-of-list:array last-of-list:array
least-common-multiple-(LCM):math
log-function-name:function log-function-name:function
measure-time-taken-by-function:utility measure-time-taken-by-function:utility
median-of-array-of-numbers:array median-of-array-of-numbers:array
@ -71,7 +73,6 @@ pick:array
pipe-functions:function pipe-functions:function
powerset:math powerset:math
promisify:function promisify:function
pull:array
random-integer-in-range:math random-integer-in-range:math
random-number-in-range:math random-number-in-range:math
read-file-as-array-of-lines:node read-file-as-array-of-lines:node
@ -99,4 +100,4 @@ URL-parameters:utility
UUID-generator:utility UUID-generator:utility
validate-email:utility validate-email:utility
validate-number:utility validate-number:utility
write-json-to-file: write-JSON-to-file:node