Travis build: 1211 [custom]
This commit is contained in:
@ -4744,6 +4744,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
|
||||
|
||||
|
||||
|
||||
|
||||
const lengthIs4 = checkProp(l => l === 4, 'length');
|
||||
lengthIs4([]); // false
|
||||
lengthIs4([1,2,3,4]); // true
|
||||
|
||||
@ -162,6 +162,7 @@ console<span class="token punctuation">.</span><span class="token function">log<
|
||||
|
||||
|
||||
|
||||
|
||||
<span class="token keyword">const</span> lengthIs4 <span class="token operator">=</span> <span class="token function">checkProp</span><span class="token punctuation">(</span>l <span class="token operator">=></span> l <span class="token operator">===</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token string">'length'</span><span class="token punctuation">);</span>
|
||||
<span class="token function">lengthIs4</span><span class="token punctuation">([]);</span> <span class="token comment">// false</span>
|
||||
<span class="token function">lengthIs4</span><span class="token punctuation">([</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">]);</span> <span class="token comment">// true</span>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -386,7 +386,7 @@
|
||||
"archived": false
|
||||
},
|
||||
"meta": {
|
||||
"hash": "d0eace2a9fcd0b8e056083e8c3e92574d7da0eee62c6897f7d6c5a94e64a3841"
|
||||
"hash": "e2fe0ff4736e09c616dda81905f39b89a213f4ea1d9d8fec7fb4c393a656ad72"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -568,7 +568,7 @@
|
||||
},
|
||||
"meta": {
|
||||
"archived": false,
|
||||
"hash": "d0eace2a9fcd0b8e056083e8c3e92574d7da0eee62c6897f7d6c5a94e64a3841"
|
||||
"hash": "e2fe0ff4736e09c616dda81905f39b89a213f4ea1d9d8fec7fb4c393a656ad72"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -27,6 +27,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
|
||||
|
||||
|
||||
|
||||
|
||||
const lengthIs4 = checkProp(l => l === 4, 'length');
|
||||
lengthIs4([]); // false
|
||||
lengthIs4([1,2,3,4]); // true
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
These snippets, while useful and interesting, didn't quite make it into the repository due to either having very specific use-cases or being outdated. However we felt like they might still be useful to some readers, so here they are.
|
||||
## Table of Contents
|
||||
* [`JSONToDate`](#jsontodate)
|
||||
* [`squareSum`](#squaresum)
|
||||
* [`binarySearch`](#binarysearch)
|
||||
* [`celsiusToFahrenheit`](#celsiustofahrenheit)
|
||||
* [`cleanObj`](#cleanobj)
|
||||
@ -14,7 +15,6 @@ These snippets, while useful and interesting, didn't quite make it into the repo
|
||||
* [`fibonacciUntilNum`](#fibonacciuntilnum)
|
||||
* [`heronArea`](#heronarea)
|
||||
* [`howManyTimes`](#howmanytimes)
|
||||
* [`httpDelete`](#httpdelete)
|
||||
* [`httpPut`](#httpput)
|
||||
* [`isArmstrongNumber`](#isarmstrongnumber)
|
||||
* [`isSimilar`](#issimilar)
|
||||
@ -26,7 +26,7 @@ These snippets, while useful and interesting, didn't quite make it into the repo
|
||||
* [`removeVowels`](#removevowels)
|
||||
* [`solveRPN`](#solverpn)
|
||||
* [`speechSynthesis`](#speechsynthesis)
|
||||
* [`squareSum`](#squaresum)
|
||||
* [`httpDelete`](#httpdelete)
|
||||
|
||||
---
|
||||
### JSONToDate
|
||||
@ -53,6 +53,27 @@ JSONToDate(/Date(1489525200000)/); // "14/3/2017"
|
||||
|
||||
<br>[⬆ Back to top](#contents)
|
||||
|
||||
### squareSum
|
||||
|
||||
Squares each number in an array and then sums the results together.
|
||||
|
||||
Use `Array.prototype.reduce()` in combination with `Math.pow()` to iterate over numbers and sum their squares into an accumulator.
|
||||
|
||||
```js
|
||||
const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
squareSum(1, 2, 2); // 9
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#contents)
|
||||
|
||||
### binarySearch
|
||||
|
||||
Use recursion. Similar to `Array.prototype.indexOf()` that finds the index of a value within an array.
|
||||
@ -367,38 +388,6 @@ howManyTimes(100, -1); // Infinity
|
||||
|
||||
<br>[⬆ Back to top](#contents)
|
||||
|
||||
### httpDelete
|
||||
|
||||
Makes a `DELETE` request to the passed URL.
|
||||
|
||||
Use `XMLHttpRequest` web api to make a `delete` request to the given `url`.
|
||||
Handle the `onload` event, by running the provided `callback` function.
|
||||
Handle the `onerror` event, by running the provided `err` function.
|
||||
Omit the third argument, `err` to log the request to the console's error stream by default.
|
||||
|
||||
```js
|
||||
const httpDelete = (url, callback, err = console.error) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open('DELETE', url, true);
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send();
|
||||
};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
httpDelete('https://website.com/users/123', request => {
|
||||
console.log(request.responseText);
|
||||
}); // 'Deletes a user from the database'
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#contents)
|
||||
|
||||
### httpPut
|
||||
|
||||
Makes a `PUT` request to the passed URL.
|
||||
@ -739,21 +728,32 @@ speechSynthesis('Hello, World'); // // plays the message
|
||||
|
||||
<br>[⬆ Back to top](#contents)
|
||||
|
||||
### squareSum
|
||||
### httpDelete
|
||||
|
||||
Squares each number in an array and then sums the results together.
|
||||
Makes a `DELETE` request to the passed URL.
|
||||
|
||||
Use `Array.prototype.reduce()` in combination with `Math.pow()` to iterate over numbers and sum their squares into an accumulator.
|
||||
Use `XMLHttpRequest` web api to make a `delete` request to the given `url`.
|
||||
Handle the `onload` event, by running the provided `callback` function.
|
||||
Handle the `onerror` event, by running the provided `err` function.
|
||||
Omit the third argument, `err` to log the request to the console's error stream by default.
|
||||
|
||||
```js
|
||||
const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0);
|
||||
const httpDelete = (url, callback, err = console.error) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open('DELETE', url, true);
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send();
|
||||
};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
squareSum(1, 2, 2); // 9
|
||||
httpDelete('https://website.com/users/123', request => {
|
||||
console.log(request.responseText);
|
||||
}); // 'Deletes a user from the database'
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
Reference in New Issue
Block a user