From 7c128fdb5bb30f6939e578d9a036b2aba79b1bc9 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Wed, 5 Jun 2019 09:55:25 +0000 Subject: [PATCH] Travis build: 1211 [custom] --- README.md | 1 + docs/function.html | 1 + docs/index.html | 2 +- snippet_data/snippetList.json | 2 +- snippet_data/snippets.json | 2 +- snippets/checkProp.md | 1 + snippets_archive/README.md | 78 +++++++++++++++++------------------ 7 files changed, 45 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index fabe09e29..a4b494a26 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/function.html b/docs/function.html index 7bbd2d24f..b46eb8eda 100644 --- a/docs/function.html +++ b/docs/function.html @@ -162,6 +162,7 @@ console.log< + const lengthIs4 = checkProp(l => l === 4, 'length'); lengthIs4([]); // false lengthIs4([1,2,3,4]); // true diff --git a/docs/index.html b/docs/index.html index 16c3b5021..bb3015f5c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -93,7 +93,7 @@ },1700); } }, false); - }

logo 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.



Array

all

Returns true if the provided predicate function returns true for all elements in a collection, false otherwise.

Use Array.prototype.every() to test if all elements in the collection return true based on fn. Omit the second argument, fn, to use Boolean as a default.

const all = (arr, fn = Boolean) => arr.every(fn);
+      }

logo 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.



Array

all

Returns true if the provided predicate function returns true for all elements in a collection, false otherwise.

Use Array.prototype.every() to test if all elements in the collection return true based on fn. Omit the second argument, fn, to use Boolean as a default.

const all = (arr, fn = Boolean) => arr.every(fn);
 
all([4, 2, 3], x => x > 1); // true
 all([1, 2, 3]); // true
 

allEqual

Check if all elements in an array are equal.

Use Array.prototype.every() to check if all the elements of the array are the same as the first one. Elements in the array are compared using the strict comparison operator, which does not account for NaN self-inequality.

const allEqual = arr => arr.every(val => val === arr[0]);
diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json
index 76a53ca55..045a0e15e 100644
--- a/snippet_data/snippetList.json
+++ b/snippet_data/snippetList.json
@@ -386,7 +386,7 @@
         "archived": false
       },
       "meta": {
-        "hash": "d0eace2a9fcd0b8e056083e8c3e92574d7da0eee62c6897f7d6c5a94e64a3841"
+        "hash": "e2fe0ff4736e09c616dda81905f39b89a213f4ea1d9d8fec7fb4c393a656ad72"
       }
     },
     {
diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json
index 470250c5c..6ee5e5902 100644
--- a/snippet_data/snippets.json
+++ b/snippet_data/snippets.json
@@ -568,7 +568,7 @@
       },
       "meta": {
         "archived": false,
-        "hash": "d0eace2a9fcd0b8e056083e8c3e92574d7da0eee62c6897f7d6c5a94e64a3841"
+        "hash": "e2fe0ff4736e09c616dda81905f39b89a213f4ea1d9d8fec7fb4c393a656ad72"
       }
     },
     {
diff --git a/snippets/checkProp.md b/snippets/checkProp.md
index 67b318e19..07de4a069 100644
--- a/snippets/checkProp.md
+++ b/snippets/checkProp.md
@@ -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
diff --git a/snippets_archive/README.md b/snippets_archive/README.md
index 6dae41d35..feca993a2 100644
--- a/snippets_archive/README.md
+++ b/snippets_archive/README.md
@@ -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"
 
 
[⬆ 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); +``` + +
+Examples + +```js +squareSum(1, 2, 2); // 9 +``` + +
+ +
[⬆ 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
[⬆ 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(); -}; -``` - -
-Examples - -```js -httpDelete('https://website.com/users/123', request => { - console.log(request.responseText); -}); // 'Deletes a user from the database' -``` - -
- -
[⬆ Back to top](#contents) - ### httpPut Makes a `PUT` request to the passed URL. @@ -739,21 +728,32 @@ speechSynthesis('Hello, World'); // // plays the message
[⬆ 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(); +}; ```
Examples ```js -squareSum(1, 2, 2); // 9 +httpDelete('https://website.com/users/123', request => { + console.log(request.responseText); +}); // 'Deletes a user from the database' ```