Travis build: 1298

This commit is contained in:
30secondsofcode
2019-07-19 06:31:59 +00:00
parent b1f7b1d4da
commit 82ff65e607
4 changed files with 61 additions and 58 deletions

113
README.md
View File

@ -2,7 +2,7 @@
# 30 seconds of code
[![License](https://img.shields.io/badge/license-CC0--1.0-blue.svg)](https://github.com/30-seconds/30-seconds-of-code/blob/master/LICENSE) [![npm Downloads](https://img.shields.io/npm/dt/30-seconds-of-code.svg)](https://www.npmjs.com/package/30-seconds-of-code) [![npm Version](https://img.shields.io/npm/v/30-seconds-of-code.svg)](https://www.npmjs.com/package/30-seconds-of-code) [![Known Vulnerabilities](https://snyk.io/test/github/30-seconds/30-seconds-of-code/badge.svg?targetFile=package.json)](https://snyk.io/test/github/30-seconds/30-seconds-of-code?targetFile=package.json) <br/>
[![License](https://img.shields.io/badge/license-CC0--1.0-blue.svg)](https://github.com/30-seconds/30-seconds-of-code/blob/master/LICENSE) [![npm Downloads](https://img.shields.io/npm/dt/30-seconds-of-code.svg)](https://www.npmjs.com/package/30-seconds-of-code) [![npm Version](https://img.shields.io/npm/v/30-seconds-of-code.svg)](https://www.npmjs.com/package/30-seconds-of-code) [![Known Vulnerabilities](https://snyk.io/test/github/30-seconds/30-seconds-of-code/badge.svg?targetFile=package.json)](https://snyk.io/test/github/30-seconds/30-seconds-of-code?targetFile=package.json) <br/>
[![Travis Build](https://travis-ci.com/30-seconds/30-seconds-of-code.svg?branch=master)](https://travis-ci.com/30-seconds/30-seconds-of-code) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/6ab7791fb1ea40b4a576d658fb96807f)](https://www.codacy.com/app/Chalarangelo/30-seconds-of-code?utm_source=github.com&utm_medium=referral&utm_content=30-seconds/30-seconds-of-code&utm_campaign=Badge_Grade) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg)](https://github.com/Flet/semistandard) <br/>
[![Awesome](https://awesome.re/badge.svg)](https://awesome.re) [![ProductHunt](https://img.shields.io/badge/producthunt-vote-orange.svg)](https://www.producthunt.com/posts/30-seconds-of-code) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)
@ -531,12 +531,12 @@ const firstTwoMax = ary(Math.max, 2);
<br>[⬆ Back to top](#contents)
### 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.
### 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.
```js
const call = (key, ...args) => context => context[key](...args);
```
@ -552,18 +552,18 @@ const map = call.bind(null, 'map');
Promise.resolve([1, 2, 3])
.then(map(x => 2 * x))
.then(console.log); // [ 2, 4, 6 ]
```
```
</details>
<br>[⬆ Back to top](#contents)
### collectInto
Changes a function that accepts an array into a variadic function.
Given a function, return a closure that collects all inputs into an array-accepting function.
### collectInto
Changes a function that accepts an array into a variadic function.
Given a function, return a closure that collects all inputs into an array-accepting function.
```js
const collectInto = fn => (...args) => fn(args);
```
@ -577,18 +577,18 @@ let p1 = Promise.resolve(1);
let p2 = Promise.resolve(2);
let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3));
Pall(p1, p2, p3).then(console.log); // [1, 2, 3] (after about 2 seconds)
```
```
</details>
<br>[⬆ Back to top](#contents)
### flip
Flip takes a function as an argument, then makes the first argument the last.
Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest.
### flip
Flip takes a function as an argument, then makes the first argument the last.
Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest.
```js
const flip = fn => (first, ...rest) => fn(...rest, first);
```
@ -604,7 +604,7 @@ let mergePerson = mergeFrom.bind(null, a);
mergePerson(b); // == b
b = {};
Object.assign(b, a); // == b
```
```
</details>
@ -767,12 +767,12 @@ rearged('b', 'c', 'a'); // ['a', 'b', 'c']
<br>[⬆ Back to top](#contents)
### spreadOver
Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function.
Use closures and the spread operator (`...`) to map the array of arguments to the inputs of the function.
### spreadOver
Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function.
Use closures and the spread operator (`...`) to map the array of arguments to the inputs of the function.
```js
const spreadOver = fn => argsArr => fn(...argsArr);
```
@ -783,7 +783,7 @@ const spreadOver = fn => argsArr => fn(...argsArr);
```js
const arrayMax = spreadOver(Math.max);
arrayMax([1, 2, 3]); // 3
```
```
</details>
@ -1262,12 +1262,12 @@ everyNth([1, 2, 3, 4, 5, 6], 2); // [ 2, 4, 6 ]
<br>[⬆ Back to top](#contents)
### filterFalsy
Filters out the falsy values in an array.
Use `Array.prototype.filter()` to get an array containing only truthy values.
### filterFalsy
Filters out the falsy values in an array.
Use `Array.prototype.filter()` to get an array containing only truthy values.
```js
const filterFalsy = arr => arr.filter(Boolean);
```
@ -1277,7 +1277,7 @@ const filterFalsy = arr => arr.filter(Boolean);
```js
filterFalsy(['', true, {}, false, 'sample', 1, 0]); // [true, {}, 'sample', 1]
```
```
</details>
@ -3283,7 +3283,7 @@ bottomVisible(); // true
⚠️ **NOTICE:** The same functionality can be easily implemented by using the new asynchronous Clipboard API, which is still experimental but should be used in the future instead of this snippet. Find out more about it [here](https://github.com/w3c/clipboard-apis/blob/master/explainer.adoc#writing-to-the-clipboard).
Copy a string to the clipboard.
Copy a string to the clipboard.
Only works as a result of user action (i.e. inside a `click` event listener).
Create a new `<textarea>` element, fill it with the supplied data and add it to the HTML document.
@ -3360,11 +3360,11 @@ counter('#my-id', 1, 1000, 5, 2000); // Creates a 2-second timer for the element
### createElement
Creates an element from a string (without appending it to the document).
Creates an element from a string (without appending it to the document).
If the given string contains multiple elements, only the first one will be returned.
Use `document.createElement()` to create a new element.
Set its `innerHTML` to the string supplied as the argument.
Set its `innerHTML` to the string supplied as the argument.
Use `ParentNode.firstElementChild` to return the element version of the string.
```js
@ -3867,7 +3867,7 @@ obs.disconnect(); // Disconnects the observer and stops logging mutations on the
Removes an event listener from an element.
Use `EventTarget.removeEventListener()` to remove an event listener from an element.
Use `EventTarget.removeEventListener()` to remove an event listener from an element.
Omit the fourth argument `opts` to use `false` or specify it based on the options used when the event listener was added.
```js
@ -3921,7 +3921,7 @@ on(document.body, 'click', fn, { options: true }); // use capturing instead of b
Run the callback whenever the user input type changes (`mouse` or `touch`). Useful for enabling/disabling code depending on the input device. This process is dynamic and works with hybrid devices (e.g. touchscreen laptops).
Use two event listeners. Assume `mouse` input initially and bind a `touchstart` event listener to the document.
Use two event listeners. Assume `mouse` input initially and bind a `touchstart` event listener to the document.
On `touchstart`, add a `mousemove` event listener to listen for two consecutive `mousemove` events firing within 20ms, using `performance.now()`.
Run the callback with the input type as an argument in either of these situations.
@ -3988,9 +3988,9 @@ prefix('appearance'); // 'appearance' on a supported browser, otherwise 'webkitA
Invokes the provided callback on each animation frame.
Use recursion.
Provided that `running` is `true`, continue invoking `window.requestAnimationFrame()` which invokes the provided callback.
Return an object with two methods `start` and `stop` to allow manual control of the recording.
Use recursion.
Provided that `running` is `true`, continue invoking `window.requestAnimationFrame()` which invokes the provided callback.
Return an object with two methods `start` and `stop` to allow manual control of the recording.
Omit the second argument, `autoStart`, to implicitly call `start` when the function is invoked.
```js
@ -4204,7 +4204,7 @@ show(...document.querySelectorAll('img')); // Shows all <img> elements on the pa
Smoothly scrolls the element on which it's called into the visible area of the browser window.
Use `.scrollIntoView` method to scroll the element.
Use `.scrollIntoView` method to scroll the element.
Pass `{ behavior: 'smooth' }` to `.scrollIntoView` so it scrolls smoothly.
```js
@ -4557,7 +4557,7 @@ minDate(array); // 2016-01-08T22:00:00.000Z
Results in a string representation of tomorrow's date.
Use `new Date()` to get the current date, increment by one using `Date.getDate()` and set the value to the result using `Date.setDate()`.
Use `new Date()` to get the current date, increment by one using `Date.getDate()` and set the value to the result using `Date.setDate()`.
Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
```js
@ -4735,6 +4735,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
const lengthIs4 = checkProp(l => l === 4, 'length');
lengthIs4([]); // false
lengthIs4([1,2,3,4]); // true
@ -4975,11 +4976,11 @@ functionName(Math.max); // max (logged in debug channel of console)
### hz
Returns the number of times a function executed per second.
Returns the number of times a function executed per second.
`hz` is the unit for `hertz`, the unit of frequency defined as one cycle per second.
Use `performance.now()` to get the difference in milliseconds before and after the iteration loop to calculate the time elapsed executing the function `iterations` times.
Return the number of cycles per second by converting milliseconds to seconds and dividing it by the time elapsed.
Use `performance.now()` to get the difference in milliseconds before and after the iteration loop to calculate the time elapsed executing the function `iterations` times.
Return the number of cycles per second by converting milliseconds to seconds and dividing it by the time elapsed.
Omit the second argument, `iterations`, to use the default of 100 iterations.
```js
@ -5333,7 +5334,7 @@ unfold(f, 10); // [-10, -20, -30, -40, -50]
### when
Tests a value, `x`, against a predicate function. If `true`, return `fn(x)`. Else, return `x`.
Tests a value, `x`, against a predicate function. If `true`, return `fn(x)`. Else, return `x`.
Return a function expecting a single value, `x`, that returns the appropriate value based on `pred`.
@ -5556,7 +5557,7 @@ The array should be ordered from best performer to worst performer (winner -> lo
Use the exponent `**` operator and math operators to compute the expected score (chance of winning).
of each opponent and compute the new rating for each.
Loop through the ratings, using each permutation to compute the post-Elo rating for each player in a pairwise fashion.
Loop through the ratings, using each permutation to compute the post-Elo rating for each player in a pairwise fashion.
Omit the second argument to use the default `kFactor` of 32.
```js
@ -6906,7 +6907,7 @@ o[1][0] = 4; // not allowed as well
Returns the target value in a nested JSON object, based on the `keys` array.
Compare the keys you want in the nested JSON object as an `Array`.
Use `Array.prototype.reduce()` to get value from nested JSON object one by one.
Use `Array.prototype.reduce()` to get value from nested JSON object one by one.
If the key exists in object, return target value, otherwise, return `null`.
```js
@ -6940,7 +6941,7 @@ Deep maps an object keys.
Creates an object with the same values as the provided object and keys generated by running the provided function for each key.
Use `Object.keys(obj)` to iterate over the object's keys.
Use `Object.keys(obj)` to iterate over the object's keys.
Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
```js
@ -7754,7 +7755,7 @@ const b = shallowClone(a); // a !== b
Get size of arrays, objects or strings.
Get type of `val` (`array`, `object` or `string`).
Get type of `val` (`array`, `object` or `string`).
Use `length` property for arrays.
Use `length` or `size` value if available or number of keys for objects.
Use `size` of a [`Blob` object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) created from `val` for strings.
@ -8967,7 +8968,7 @@ isNull(null); // true
Checks if the given argument is a number.
Use `typeof` to check if a value is classified as a number primitive.
Use `typeof` to check if a value is classified as a number primitive.
To safeguard against `NaN`, check if `val === val` (as `NaN` has a `typeof` equal to `number` and is the only value not equal to itself).
```js
@ -8991,7 +8992,7 @@ isNumber(NaN); // false
Returns a boolean determining if the passed value is an object or not.
Uses the `Object` constructor to create an object wrapper for the given value.
Uses the `Object` constructor to create an object wrapper for the given value.
If the value is `null` or `undefined`, create and return an empty object. Οtherwise, return an object of a type that corresponds to the given value.
```js

View File

@ -515,8 +515,8 @@
<ul>
<li><a href="https://30-seconds.github.io/30-seconds-of-css/">30 seconds of CSS</a></li>
<li><a href="http://30secondsofinterviews.org/">30 seconds of Interviews</a> by <strong>fejes713</strong></li>
<li><a href="https://github.com/kriadmin/30-seconds-of-python-code">30 seconds of Python</a> <em>(unofficial)</em></li>
<li><a href="https://github.com/appzcoder/30-seconds-of-php-code">30 seconds of PHP</a> <em>(unofficial)</em></li>
<li><a href="https://github.com/30-seconds/30-seconds-of-python-code">30 seconds of Python</a></li>
<li><a href="https://github.com/30-seconds/30-seconds-of-php-code">30 seconds of PHP</a></li>
</ul><br />
<h2 class="category-name">Maintainers</h2>
<div class="flex-row">

View File

@ -153,6 +153,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>

View File

@ -18,6 +18,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
const lengthIs4 = checkProp(l => l === 4, 'length');
lengthIs4([]); // false
lengthIs4([1,2,3,4]); // true