Travis build: 347
This commit is contained in:
130
README.md
130
README.md
@ -17,6 +17,7 @@
|
||||
* [`call`](#call)
|
||||
* [`collectInto`](#collectinto)
|
||||
* [`flip`](#flip)
|
||||
* [`pipeFunctions`](#pipefunctions)
|
||||
* [`promisify`](#promisify)
|
||||
* [`spreadOver`](#spreadover)
|
||||
|
||||
@ -121,6 +122,7 @@
|
||||
* [`randomIntegerInRange`](#randomintegerinrange)
|
||||
* [`randomNumberInRange`](#randomnumberinrange)
|
||||
* [`round`](#round)
|
||||
* [`sdbmHashAlgorithm`](#sdbmhashalgorithm)
|
||||
* [`standardDeviation`](#standarddeviation)
|
||||
|
||||
### Media
|
||||
@ -167,6 +169,7 @@
|
||||
* [`isNumber`](#isnumber)
|
||||
* [`isString`](#isstring)
|
||||
* [`isSymbol`](#issymbol)
|
||||
* [`randomHexColor`](#randomhexcolor)
|
||||
* [`RGBToHex`](#rgbtohex)
|
||||
* [`timeTaken`](#timetaken)
|
||||
* [`toDecimalMark`](#todecimalmark)
|
||||
@ -174,11 +177,6 @@
|
||||
* [`UUIDGenerator`](#uuidgenerator)
|
||||
* [`validateNumber`](#validatenumber)
|
||||
|
||||
### _Uncategorized_
|
||||
* [`pipeFunctions`](#pipefunctions)
|
||||
* [`randomHexColor`](#randomhexcolor)
|
||||
* [`sdbmHashAlgorithm`](#sdbmhashalgorithm)
|
||||
|
||||
## Adapter
|
||||
|
||||
### call
|
||||
@ -238,6 +236,25 @@ Object.assign(b, a) // == b
|
||||
|
||||
[⬆ back to top](#table-of-contents)
|
||||
|
||||
### pipeFunctions
|
||||
|
||||
Performs left-to-right function composition.
|
||||
|
||||
Use `Array.reduce()` with the spread operator (`...`) to perform left-to-right function composition.
|
||||
The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.
|
||||
|
||||
```js
|
||||
const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
|
||||
/*
|
||||
const add5 = x => x + 5
|
||||
const multiply = (x, y) => x * y
|
||||
const multiplyAndAdd5 = pipeFunctions(multiply, add5)
|
||||
multiplyAndAdd5(5, 2) -> 15
|
||||
*/
|
||||
```
|
||||
|
||||
[⬆ back to top](#table-of-contents)
|
||||
|
||||
### promisify
|
||||
|
||||
Converts an asynchronous function to return a promise.
|
||||
@ -1696,6 +1713,25 @@ const round = (n, decimals=0) => Number(`${Math.round(`${n}e${decimals}`)}e-${de
|
||||
|
||||
[⬆ back to top](#table-of-contents)
|
||||
|
||||
### sdbmHashAlgorithm
|
||||
|
||||
This algorithm is a simple hash-algorithm that hashes it input string `s` into a whole number.
|
||||
|
||||
Use `split('')` and `Array.reduce()` to create a hash of the input string, utilizing bit shifting.
|
||||
|
||||
``` js
|
||||
const sdbm = str => {
|
||||
let arr = str.split('');
|
||||
return arr.reduce((hashCode, currentVal) =>
|
||||
hashCode = currentVal.charCodeAt(0) + (hashCode << 6) + (hashCode << 16) - hashCode
|
||||
,0)
|
||||
}
|
||||
// console.log(sdbm("name")) // -3521204949
|
||||
// console.log(sdbm("age")) // 808122783
|
||||
```
|
||||
|
||||
[⬆ back to top](#table-of-contents)
|
||||
|
||||
### standardDeviation
|
||||
|
||||
Returns the standard deviation of an array of numbers.
|
||||
@ -1794,12 +1830,12 @@ const cleanObj = (obj, keysToKeep = [], childIndicator) => {
|
||||
} else if (!keysToKeep.includes(key)) {
|
||||
delete obj[key];
|
||||
}
|
||||
})
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
/*
|
||||
const testObj = {a: 1, b: 2, children: {a: 1, b: 2}}
|
||||
cleanObj(testObj, ["a"],"children")
|
||||
console.log(testObj)// { a: 1, children : { a: 1}}
|
||||
cleanObj(testObj, ["a"],"children") // { a: 1, children : { a: 1}}
|
||||
*/
|
||||
```
|
||||
|
||||
@ -2307,6 +2343,25 @@ const isSymbol = val => typeof val === 'symbol';
|
||||
|
||||
[⬆ back to top](#table-of-contents)
|
||||
|
||||
### randomHexColor
|
||||
|
||||
Generates a random hexadecimal color code.
|
||||
|
||||
Use `Math.random` to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using `toString(16)`.
|
||||
|
||||
```js
|
||||
const randomHexColor = () => {
|
||||
let n = (Math.random()*0xfffff|0).toString(16);
|
||||
return '#' + (n.length !== 6
|
||||
? (Math.random()*0xf|0).toString(16) + n : n);
|
||||
}
|
||||
// randomHexColorCode() -> "#e34155"
|
||||
// randomHexColorCode() -> "#fd73a6"
|
||||
// randomHexColorCode() -> "#4144c6"
|
||||
```
|
||||
|
||||
[⬆ back to top](#table-of-contents)
|
||||
|
||||
### RGBToHex
|
||||
|
||||
Converts the values of RGB components to a color code.
|
||||
@ -2397,65 +2452,6 @@ const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) ==
|
||||
// validateNumber('10') -> true
|
||||
```
|
||||
|
||||
[⬆ back to top](#table-of-contents)
|
||||
## _Uncategorized_
|
||||
|
||||
### pipeFunctions
|
||||
|
||||
Performs left-to-right function composition.
|
||||
|
||||
Use `Array.reduce()` with the spread operator (`...`) to perform left-to-right function composition.
|
||||
The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.
|
||||
|
||||
```js
|
||||
const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
|
||||
/*
|
||||
const add5 = x => x + 5
|
||||
const multiply = (x, y) => x * y
|
||||
const multiplyAndAdd5 = pipeFunctions(multiply, add5)
|
||||
multiplyAndAdd5(5, 2) -> 15
|
||||
*/
|
||||
```
|
||||
|
||||
[⬆ back to top](#table-of-contents)
|
||||
|
||||
### randomHexColor
|
||||
|
||||
Generates a random hexadecimal color code.
|
||||
|
||||
Use `Math.random` to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using `toString(16)`.
|
||||
|
||||
```js
|
||||
const randomHexColor = () => {
|
||||
let n = (Math.random()*0xfffff|0).toString(16);
|
||||
return '#' + (n.length !== 6
|
||||
? (Math.random()*0xf|0).toString(16) + n : n);
|
||||
}
|
||||
// randomHexColorCode() -> "#e34155"
|
||||
// randomHexColorCode() -> "#fd73a6"
|
||||
// randomHexColorCode() -> "#4144c6"
|
||||
```
|
||||
|
||||
[⬆ back to top](#table-of-contents)
|
||||
|
||||
### sdbmHashAlgorithm
|
||||
|
||||
This algorithm is a simple hash-algorithm that hashes it input string `s` into a whole number.
|
||||
|
||||
Use `split('')` and `Array.reduce()` to create a hash of the input string, utilizing bit shifting.
|
||||
|
||||
``` js
|
||||
const sdbm = str => {
|
||||
let arr = str.split('');
|
||||
return arr.reduce((hashCode, currentVal) =>
|
||||
hashCode = currentVal.charCodeAt(0) + (hashCode << 6) + (hashCode << 16) - hashCode
|
||||
,0)
|
||||
}
|
||||
// console.log(sdbm("name")) // -3521204949
|
||||
// console.log(sdbm("age")) // 808122783
|
||||
```
|
||||
|
||||
|
||||
[⬆ back to top](#table-of-contents)
|
||||
|
||||
## Credits
|
||||
|
||||
@ -78,6 +78,7 @@
|
||||
</h3><a class="sublink-1" href="#call">call</a>
|
||||
<a class="sublink-1" href="#collectinto">collectInto</a>
|
||||
<a class="sublink-1" href="#flip">flip</a>
|
||||
<a class="sublink-1" href="#pipefunctions">pipeFunctions</a>
|
||||
<a class="sublink-1" href="#promisify">promisify</a>
|
||||
<a class="sublink-1" href="#spreadover">spreadOver</a>
|
||||
|
||||
@ -182,6 +183,7 @@
|
||||
<a class="sublink-1" href="#randomintegerinrange">randomIntegerInRange</a>
|
||||
<a class="sublink-1" href="#randomnumberinrange">randomNumberInRange</a>
|
||||
<a class="sublink-1" href="#round">round</a>
|
||||
<a class="sublink-1" href="#sdbmhashalgorithm">sdbmHashAlgorithm</a>
|
||||
<a class="sublink-1" href="#standarddeviation">standardDeviation</a>
|
||||
|
||||
<h3>Media
|
||||
@ -228,6 +230,7 @@
|
||||
<a class="sublink-1" href="#isnumber">isNumber</a>
|
||||
<a class="sublink-1" href="#isstring">isString</a>
|
||||
<a class="sublink-1" href="#issymbol">isSymbol</a>
|
||||
<a class="sublink-1" href="#randomhexcolor">randomHexColor</a>
|
||||
<a class="sublink-1" href="#rgbtohex">RGBToHex</a>
|
||||
<a class="sublink-1" href="#timetaken">timeTaken</a>
|
||||
<a class="sublink-1" href="#todecimalmark">toDecimalMark</a>
|
||||
@ -235,11 +238,6 @@
|
||||
<a class="sublink-1" href="#uuidgenerator">UUIDGenerator</a>
|
||||
<a class="sublink-1" href="#validatenumber">validateNumber</a>
|
||||
|
||||
<h3>Uncategorized
|
||||
</h3><a class="sublink-1" href="#pipefunctions">pipeFunctions</a>
|
||||
<a class="sublink-1" href="#randomhexcolor">randomHexColor</a>
|
||||
<a class="sublink-1" href="#sdbmhashalgorithm">sdbmHashAlgorithm</a>
|
||||
|
||||
</nav><main class="col-sm-12 col-md-8 col-lg-9" style="height:100%;overflow-y:auto;background:#eceef2;padding:0"><a id="top"> </a><h2 style="text-align:center">Adapter</h2>
|
||||
<div class="card fluid"><div class="section double-padded"><h3 id="call">call</h3></div><div class="section double-padded">
|
||||
<p>Given a key and a set of arguments, call them when given a context. Primarily useful in composition.</p>
|
||||
@ -277,6 +275,18 @@ b = {}
|
||||
Object.assign(b, a) // == b
|
||||
*/
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="pipefunctions">pipeFunctions</h3></div><div class="section double-padded">
|
||||
<p>Performs left-to-right function composition.</p>
|
||||
<p>Use <code>Array.reduce()</code> with the spread operator (<code>...</code>) to perform left-to-right function composition.
|
||||
The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.</p>
|
||||
<pre><code class="language-js">const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
|
||||
/*
|
||||
const add5 = x => x + 5
|
||||
const multiply = (x, y) => x * y
|
||||
const multiplyAndAdd5 = pipeFunctions(multiply, add5)
|
||||
multiplyAndAdd5(5, 2) -> 15
|
||||
*/
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="promisify">promisify</h3></div><div class="section double-padded">
|
||||
<p>Converts an asynchronous function to return a promise.</p>
|
||||
<p>Use currying to return a function returning a <code>Promise</code> that calls the original function.
|
||||
@ -1089,6 +1099,18 @@ Omit the second argument, <code>decimals</code> to round to an integer.</p>
|
||||
<pre><code class="language-js">const round = (n, decimals=0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`);
|
||||
// round(1.005, 2) -> 1.01
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="sdbmhashalgorithm">sdbmHashAlgorithm</h3></div><div class="section double-padded">
|
||||
<p>This algorithm is a simple hash-algorithm that hashes it input string <code>s</code> into a whole number.</p>
|
||||
<p>Use <code>split('')</code> and <code>Array.reduce()</code> to create a hash of the input string, utilizing bit shifting.</p>
|
||||
<pre><code class="language-js">const sdbm = str => {
|
||||
let arr = str.split('');
|
||||
return arr.reduce((hashCode, currentVal) =>
|
||||
hashCode = currentVal.charCodeAt(0) + (hashCode << 6) + (hashCode << 16) - hashCode
|
||||
,0)
|
||||
}
|
||||
// console.log(sdbm("name")) // -3521204949
|
||||
// console.log(sdbm("age")) // 808122783
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="standarddeviation">standardDeviation</h3></div><div class="section double-padded">
|
||||
<p>Returns the standard deviation of an array of numbers.</p>
|
||||
<p>Use <code>Array.reduce()</code> to calculate the mean, variance and the sum of the variance of the values, the variance of the values, then
|
||||
@ -1154,12 +1176,12 @@ Also if you give it a special key (<code>childIndicator</code>) it will search d
|
||||
} else if (!keysToKeep.includes(key)) {
|
||||
delete obj[key];
|
||||
}
|
||||
})
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
/*
|
||||
const testObj = {a: 1, b: 2, children: {a: 1, b: 2}}
|
||||
cleanObj(testObj, ["a"],"children")
|
||||
console.log(testObj)// { a: 1, children : { a: 1}}
|
||||
cleanObj(testObj, ["a"],"children") // { a: 1, children : { a: 1}}
|
||||
*/
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="objectfrompairs">objectFromPairs</h3></div><div class="section double-padded">
|
||||
@ -1448,6 +1470,18 @@ Omit the second argument to use the default regex.</p>
|
||||
// isSymbol('x') -> false
|
||||
// isSymbol(Symbol('x')) -> true
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="randomhexcolor">randomHexColor</h3></div><div class="section double-padded">
|
||||
<p>Generates a random hexadecimal color code.</p>
|
||||
<p>Use <code>Math.random</code> to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using <code>toString(16)</code>.</p>
|
||||
<pre><code class="language-js">const randomHexColor = () => {
|
||||
let n = (Math.random()*0xfffff|0).toString(16);
|
||||
return '#' + (n.length !== 6
|
||||
? (Math.random()*0xf|0).toString(16) + n : n);
|
||||
}
|
||||
// randomHexColorCode() -> "#e34155"
|
||||
// randomHexColorCode() -> "#fd73a6"
|
||||
// randomHexColorCode() -> "#4144c6"
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="rgbtohex">RGBToHex</h3></div><div class="section double-padded">
|
||||
<p>Converts the values of RGB components to a color code.</p>
|
||||
<p>Convert given RGB parameters to hexadecimal string using bitwise left-shift operator (<code><<</code>) and <code>toString(16)</code>, then <code>padStart(6,'0')</code> to get a 6-digit hexadecimal value.</p>
|
||||
@ -1499,43 +1533,6 @@ Use <code>Number()</code> to check if the coercion holds.</p>
|
||||
<pre><code class="language-js">const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n;
|
||||
// validateNumber('10') -> true
|
||||
</code></pre>
|
||||
</div></div><br/><h2 style="text-align:center">Uncategorized</h2>
|
||||
<div class="card fluid"><div class="section double-padded"><h3 id="pipefunctions">pipeFunctions</h3></div><div class="section double-padded">
|
||||
<p>Performs left-to-right function composition.</p>
|
||||
<p>Use <code>Array.reduce()</code> with the spread operator (<code>...</code>) to perform left-to-right function composition.
|
||||
The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.</p>
|
||||
<pre><code class="language-js">const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
|
||||
/*
|
||||
const add5 = x => x + 5
|
||||
const multiply = (x, y) => x * y
|
||||
const multiplyAndAdd5 = pipeFunctions(multiply, add5)
|
||||
multiplyAndAdd5(5, 2) -> 15
|
||||
*/
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="randomhexcolor">randomHexColor</h3></div><div class="section double-padded">
|
||||
<p>Generates a random hexadecimal color code.</p>
|
||||
<p>Use <code>Math.random</code> to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using <code>toString(16)</code>.</p>
|
||||
<pre><code class="language-js">const randomHexColor = () => {
|
||||
let n = (Math.random()*0xfffff|0).toString(16);
|
||||
return '#' + (n.length !== 6
|
||||
? (Math.random()*0xf|0).toString(16) + n : n);
|
||||
}
|
||||
// randomHexColorCode() -> "#e34155"
|
||||
// randomHexColorCode() -> "#fd73a6"
|
||||
// randomHexColorCode() -> "#4144c6"
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="sdbmhashalgorithm">sdbmHashAlgorithm</h3></div><div class="section double-padded">
|
||||
<p>This algorithm is a simple hash-algorithm that hashes it input string <code>s</code> into a whole number.</p>
|
||||
<p>Use <code>split('')</code> and <code>Array.reduce()</code> to create a hash of the input string, utilizing bit shifting.</p>
|
||||
<pre><code class="language-js">const sdbm = str => {
|
||||
let arr = str.split('');
|
||||
return arr.reduce((hashCode, currentVal) =>
|
||||
hashCode = currentVal.charCodeAt(0) + (hashCode << 6) + (hashCode << 16) - hashCode
|
||||
,0)
|
||||
}
|
||||
// console.log(sdbm("name")) // -3521204949
|
||||
// console.log(sdbm("age")) // 808122783
|
||||
</code></pre>
|
||||
</div></div><br/>
|
||||
<footer>
|
||||
<p style="display:inline-block"><strong>30 seconds of code</strong> is licensed under the <a href="https://github.com/Chalarangelo/30-seconds-of-code/blob/master/LICENSE">CC0-1.0</a> license.<br/>Icons made by <a href="https://www.flaticon.com/authors/smashicons">Smashicons</a> from <a href="https://www.flaticon.com/">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/">CC 3.0 BY</a>.<br/>Ribbon made by <a href="https://github.com/tholman/github-corners">Tim Holman</a> is licensed by <a href="https://opensource.org/licenses/MIT">The MIT License</a><br/>Built with the <a href="https://minicss.org">mini.css framework</a>.</p>
|
||||
|
||||
Reference in New Issue
Block a user