diff --git a/README.md b/README.md index a464a4dc2..8a54ec151 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ - [30 Seconds of CSS](https://30-seconds.github.io/30-seconds-of-css/) - [30 Seconds of Interviews](https://30secondsofinterviews.org/) -- [30 Seconds of Python](https://github.com/kriadmin/30-seconds-of-python-code) *unofficial* -= [30 Seconds of PHP](https://github.com/appzcoder/30-seconds-of-php-code) *unofficial* +- [30 Seconds of Python](https://github.com/kriadmin/30-seconds-of-python-code) *(unofficial)* +- [30 Seconds of PHP](https://github.com/appzcoder/30-seconds-of-php-code) *(unofficial)* #### Package @@ -491,15 +491,6 @@ average(1, 2, 3); -### Uncategorized - -
-View contents - -* [`pipeLog`](#pipelog) - -
- --- @@ -9147,32 +9138,6 @@ yesNo('Foo', true); // true
[⬆ Back to top](#table-of-contents) ---- - -## Uncategorized - -### pipeLog - -Use `console.log` in a pipeline as this function simply encloses it and returns the passed value. This is especially useful for debugging when you want to log a variable's value before its usage. - -Logs a value and returns it. - -```js -const pipeLog = data => console.log(data) || data; -``` - -
-Examples - -```js -pipeLog(1); // logs `1` and returns `1` -``` - -
- -
[⬆ Back to top](#table-of-contents) - - ## Collaborators | [](https://github.com/Chalarangelo)
[Angelos Chalaris](https://github.com/Chalarangelo) | [](https://github.com/flxwu)
[Felix Wu](https://github.com/Pl4gue) | [](https://github.com/fejes713)
[Stefan Feješ](https://github.com/fejes713) | [](https://github.com/kingdavidmartins)
[King David Martins](https://github.com/iamsoorena) | [](https://github.com/iamsoorena)
[Soorena Soleimani](https://github.com/iamsoorena) | diff --git a/docs/about.html b/docs/about.html index d3ba6e825..9996f6217 100644 --- a/docs/about.html +++ b/docs/about.html @@ -40,8 +40,8 @@

Maintainers

diff --git a/docs/adapter.html b/docs/adapter.html index 9eb01c65d..5498909eb 100644 --- a/docs/adapter.html +++ b/docs/adapter.html @@ -73,7 +73,7 @@ },1700); } }, false); - }

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



Adapter

ary

Creates a function that accepts up to n arguments, ignoring any additional arguments.

Call the provided function, fn, with up to n arguments, using Array.slice(0,n) and the spread operator (...).

const ary = (fn, n) => (...args) => fn(...args.slice(0, n));
+      }

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



Adapter

ary

Creates a function that accepts up to n arguments, ignoring any additional arguments.

Call the provided function, fn, with up to n arguments, using Array.slice(0,n) and the spread operator (...).

const ary = (fn, n) => (...args) => fn(...args.slice(0, n));
 
const firstTwoMax = ary(Math.max, 2);
 [[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)); // [6, 8, 10]
 

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
diff --git a/docs/archive.html b/docs/archive.html
index aaccaaa83..0fb704311 100644
--- a/docs/archive.html
+++ b/docs/archive.html
@@ -220,6 +220,8 @@
 
levenshteinDistance('30-seconds-of-code','30-seconds-of-python-code'); // 7
 const compareStrings = (string1,string2) => (100 - levenshteinDistance(string1,string2) / Math.max(string1.length,string2.length));
 compareStrings('30-seconds-of-code', '30-seconds-of-python-code'); // 99.72 (%)
+

pipeLog

Logs a value and returns it.

Use console.log to log the supplied value, combined with the || operator to return it.

const pipeLog = data => console.log(data) || data;
+
pipeLog(1); // logs `1` and returns `1`
 

quickSort

QuickSort an Array (ascending sort by default).

Use recursion. Use Array.filter and spread operator (...) to create an array that all elements with values less than the pivot come before the pivot, and all elements with values greater than the pivot come after it. If the parameter desc is truthy, return array sorts in descending order.

const quickSort = ([n, ...nums], desc) =>
   isNaN(n)
     ? []
diff --git a/docs/browser.html b/docs/browser.html
index e281d0a40..0ff9df870 100644
--- a/docs/browser.html
+++ b/docs/browser.html
@@ -73,7 +73,7 @@
             },1700);
           }
         }, false);
-      }

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



Browser

arrayToHtmlList

Converts the given array elements into <li> tags and appends them to the list of the given id.

Use Array.map(), document.querySelector(), and an anonymous inner closure to create a list of html tags.

const arrayToHtmlList = (arr, listID) =>
+      }

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



Browser

arrayToHtmlList

Converts the given array elements into <li> tags and appends them to the list of the given id.

Use Array.map(), document.querySelector(), and an anonymous inner closure to create a list of html tags.

const arrayToHtmlList = (arr, listID) =>
   (el => (
     (el = document.querySelector('#' + listID)),
     (el.innerHTML += arr.map(item => `<li>${item}</li>`).join(''))
diff --git a/docs/date.html b/docs/date.html
index cc60c0948..89bb1edf7 100644
--- a/docs/date.html
+++ b/docs/date.html
@@ -73,7 +73,7 @@
             },1700);
           }
         }, false);
-      }

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



Date

formatDuration

Returns the human readable format of the given number of milliseconds.

Divide ms with the appropriate values to obtain the appropriate values for day, hour, minute, second and millisecond. Use Object.entries() with Array.filter() to keep only non-zero values. Use Array.map() to create the string for each value, pluralizing appropriately. Use String.join(', ') to combine the values into a string.

const formatDuration = ms => {
+      }

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



Date

formatDuration

Returns the human readable format of the given number of milliseconds.

Divide ms with the appropriate values to obtain the appropriate values for day, hour, minute, second and millisecond. Use Object.entries() with Array.filter() to keep only non-zero values. Use Array.map() to create the string for each value, pluralizing appropriately. Use String.join(', ') to combine the values into a string.

const formatDuration = ms => {
   if (ms < 0) ms = -ms;
   const time = {
     day: Math.floor(ms / 86400000),
diff --git a/docs/function.html b/docs/function.html
index 1fe37192c..4b742516f 100644
--- a/docs/function.html
+++ b/docs/function.html
@@ -73,7 +73,7 @@
             },1700);
           }
         }, false);
-      }

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



Function

attempt

Attempts to invoke a function with the provided arguments, returning either the result or the caught error object.

Use a try... catch block to return either the result of the function or an appropriate error.

const attempt = (fn, ...args) => {
+      }

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



Function

attempt

Attempts to invoke a function with the provided arguments, returning either the result or the caught error object.

Use a try... catch block to return either the result of the function or an appropriate error.

const attempt = (fn, ...args) => {
   try {
     return fn(...args);
   } catch (e) {
diff --git a/docs/index.html b/docs/index.html
index 43a4cf04e..3d94d61de 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -73,7 +73,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.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.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 are equal

Use Array.every() to check if all the elements of the array are the same as the first one.

const allEqual = arr => arr.every(val => val === arr[0]);
diff --git a/docs/math.html b/docs/math.html
index 490ec24a7..7494af1ae 100644
--- a/docs/math.html
+++ b/docs/math.html
@@ -73,7 +73,7 @@
             },1700);
           }
         }, false);
-      }

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



Math

approximatelyEqual

Checks if two numbers are approximately equal to each other.

Use Math.abs() to compare the absolute difference of the two values to epsilon. Omit the third parameter, epsilon, to use a default value of 0.001.

const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
+      }

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



Math

approximatelyEqual

Checks if two numbers are approximately equal to each other.

Use Math.abs() to compare the absolute difference of the two values to epsilon. Omit the third parameter, epsilon, to use a default value of 0.001.

const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
 
approximatelyEqual(Math.PI / 2.0, 1.5708); // true
 

average

Returns the average of two or more numbers.

Use Array.reduce() to add each value to an accumulator, initialized with a value of 0, divide by the length of the array.

const average = (...nums) => nums.reduce((acc, val) => acc + val, 0) / nums.length;
 
average(...[1, 2, 3]); // 2
diff --git a/docs/node.html b/docs/node.html
index 034104957..269c45247 100644
--- a/docs/node.html
+++ b/docs/node.html
@@ -73,7 +73,7 @@
             },1700);
           }
         }, false);
-      }

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



Node

atob

Decodes a string of data which has been encoded using base-64 encoding.

Create a Buffer for the given string with base-64 encoding and use Buffer.toString('binary') to return the decoded string.

const atob = str => new Buffer(str, 'base64').toString('binary');
+      }

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



Node

atob

Decodes a string of data which has been encoded using base-64 encoding.

Create a Buffer for the given string with base-64 encoding and use Buffer.toString('binary') to return the decoded string.

const atob = str => new Buffer(str, 'base64').toString('binary');
 
atob('Zm9vYmFy'); // 'foobar'
 

btoa

Creates a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data.

Create a Buffer for the given string with binary encoding and use Buffer.toString('base64') to return the encoded string.

const btoa = str => new Buffer(str, 'binary').toString('base64');
 
btoa('foobar'); // 'Zm9vYmFy'
diff --git a/docs/object.html b/docs/object.html
index adda62b4b..d9eabd29a 100644
--- a/docs/object.html
+++ b/docs/object.html
@@ -73,7 +73,7 @@
             },1700);
           }
         }, false);
-      }

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



Object

bindAll

Binds methods of an object to the object itself, overwriting the existing method.

Use Array.forEach() to return a function that uses Function.apply() to apply the given context (obj) to fn for each function specified.

const bindAll = (obj, ...fns) =>
+      }

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



Object

bindAll

Binds methods of an object to the object itself, overwriting the existing method.

Use Array.forEach() to return a function that uses Function.apply() to apply the given context (obj) to fn for each function specified.

const bindAll = (obj, ...fns) =>
   fns.forEach(
     fn => (
       (f = obj[fn]),
diff --git a/docs/string.html b/docs/string.html
index 4ff664ef4..eb37b07a6 100644
--- a/docs/string.html
+++ b/docs/string.html
@@ -73,7 +73,7 @@
             },1700);
           }
         }, false);
-      }

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



String

byteSize

Returns the length of a string in bytes.

Convert a given string to a Blob Object and find its size.

const byteSize = str => new Blob([str]).size;
+      }

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



String

byteSize

Returns the length of a string in bytes.

Convert a given string to a Blob Object and find its size.

const byteSize = str => new Blob([str]).size;
 
byteSize('😀'); // 4
 byteSize('Hello World'); // 11
 

capitalize

Capitalizes the first letter of a string.

Use array destructuring and String.toUpperCase() to capitalize first letter, ...rest to get array of characters after first letter and then Array.join('') to make it a string again. Omit the lowerRest parameter to keep the rest of the string intact, or set it to true to convert to lowercase.

const capitalize = ([first, ...rest], lowerRest = false) =>
diff --git a/docs/type.html b/docs/type.html
index 41af5aedd..d8139d60a 100644
--- a/docs/type.html
+++ b/docs/type.html
@@ -73,7 +73,7 @@
             },1700);
           }
         }, false);
-      }

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



Type

getType

Returns the native type of a value.

Returns lowercased constructor name of value, "undefined" or "null" if value is undefined or null.

const getType = v =>
+      }

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



Type

getType

Returns the native type of a value.

Returns lowercased constructor name of value, "undefined" or "null" if value is undefined or null.

const getType = v =>
   v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
 
getType(new Set([1, 2, 3])); // 'set'
 

is

Checks if the provided value is of the specified type.

Ensure the value is not undefined or null using Array.includes(), and compare the constructor property on the value with type to check if the provided value is of the specified type.

const is = (type, val) => ![, null].includes(val) && val.constructor === type;
diff --git a/docs/utility.html b/docs/utility.html
index 9010da3c5..266ab3fa5 100644
--- a/docs/utility.html
+++ b/docs/utility.html
@@ -73,7 +73,7 @@
             },1700);
           }
         }, false);
-      }

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



Utility

castArray

Casts the provided value as an array if it's not one.

Use Array.isArray() to determine if val is an array and return it as-is or encapsulated in an array accordingly.

const castArray = val => (Array.isArray(val) ? val : [val]);
+      }

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



Utility

castArray

Casts the provided value as an array if it's not one.

Use Array.isArray() to determine if val is an array and return it as-is or encapsulated in an array accordingly.

const castArray = val => (Array.isArray(val) ? val : [val]);
 
castArray('foo'); // ['foo']
 castArray([1]); // [1]
 

cloneRegExp

Clones a regular expression.

Use new RegExp(), RegExp.source and RegExp.flags to clone the given regular expression.

const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
diff --git a/tag_database b/tag_database
index 9b4cb93fe..f9148976d 100644
--- a/tag_database
+++ b/tag_database
@@ -209,7 +209,6 @@ pick:object,array,intermediate
 pickBy:object,array,function,intermediate
 pipeAsyncFunctions:adapter,function,promise,intermediate
 pipeFunctions:adapter,function,intermediate
-pipeLog:uncategorized
 pluralize:string,intermediate
 powerset:math,beginner
 prefix:browser,utility,intermediate