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 # 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/> [![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) [![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) <br>[⬆ Back to top](#contents)
### call ### call
Given a key and a set of arguments, call them when given a context. Primarily useful in composition. 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. Use a closure to call a stored key with stored arguments.
```js ```js
const call = (key, ...args) => context => context[key](...args); const call = (key, ...args) => context => context[key](...args);
``` ```
@ -552,18 +552,18 @@ const map = call.bind(null, 'map');
Promise.resolve([1, 2, 3]) Promise.resolve([1, 2, 3])
.then(map(x => 2 * x)) .then(map(x => 2 * x))
.then(console.log); // [ 2, 4, 6 ] .then(console.log); // [ 2, 4, 6 ]
``` ```
</details> </details>
<br>[⬆ Back to top](#contents) <br>[⬆ Back to top](#contents)
### collectInto ### collectInto
Changes a function that accepts an array into a variadic function. 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. Given a function, return a closure that collects all inputs into an array-accepting function.
```js ```js
const collectInto = fn => (...args) => fn(args); const collectInto = fn => (...args) => fn(args);
``` ```
@ -577,18 +577,18 @@ let p1 = Promise.resolve(1);
let p2 = Promise.resolve(2); let p2 = Promise.resolve(2);
let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3)); let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3));
Pall(p1, p2, p3).then(console.log); // [1, 2, 3] (after about 2 seconds) Pall(p1, p2, p3).then(console.log); // [1, 2, 3] (after about 2 seconds)
``` ```
</details> </details>
<br>[⬆ Back to top](#contents) <br>[⬆ Back to top](#contents)
### flip ### flip
Flip takes a function as an argument, then makes the first argument the last. 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. Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest.
```js ```js
const flip = fn => (first, ...rest) => fn(...rest, first); const flip = fn => (first, ...rest) => fn(...rest, first);
``` ```
@ -604,7 +604,7 @@ let mergePerson = mergeFrom.bind(null, a);
mergePerson(b); // == b mergePerson(b); // == b
b = {}; b = {};
Object.assign(b, a); // == b Object.assign(b, a); // == b
``` ```
</details> </details>
@ -767,12 +767,12 @@ rearged('b', 'c', 'a'); // ['a', 'b', 'c']
<br>[⬆ Back to top](#contents) <br>[⬆ Back to top](#contents)
### spreadOver ### spreadOver
Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function. 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. Use closures and the spread operator (`...`) to map the array of arguments to the inputs of the function.
```js ```js
const spreadOver = fn => argsArr => fn(...argsArr); const spreadOver = fn => argsArr => fn(...argsArr);
``` ```
@ -783,7 +783,7 @@ const spreadOver = fn => argsArr => fn(...argsArr);
```js ```js
const arrayMax = spreadOver(Math.max); const arrayMax = spreadOver(Math.max);
arrayMax([1, 2, 3]); // 3 arrayMax([1, 2, 3]); // 3
``` ```
</details> </details>
@ -1262,12 +1262,12 @@ everyNth([1, 2, 3, 4, 5, 6], 2); // [ 2, 4, 6 ]
<br>[⬆ Back to top](#contents) <br>[⬆ Back to top](#contents)
### filterFalsy ### filterFalsy
Filters out the falsy values in an array. Filters out the falsy values in an array.
Use `Array.prototype.filter()` to get an array containing only truthy values. Use `Array.prototype.filter()` to get an array containing only truthy values.
```js ```js
const filterFalsy = arr => arr.filter(Boolean); const filterFalsy = arr => arr.filter(Boolean);
``` ```
@ -1277,7 +1277,7 @@ const filterFalsy = arr => arr.filter(Boolean);
```js ```js
filterFalsy(['', true, {}, false, 'sample', 1, 0]); // [true, {}, 'sample', 1] filterFalsy(['', true, {}, false, 'sample', 1, 0]); // [true, {}, 'sample', 1]
``` ```
</details> </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). ⚠️ **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). 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. 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 ### 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. If the given string contains multiple elements, only the first one will be returned.
Use `document.createElement()` to create a new element. 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. Use `ParentNode.firstElementChild` to return the element version of the string.
```js ```js
@ -3867,7 +3867,7 @@ obs.disconnect(); // Disconnects the observer and stops logging mutations on the
Removes an event listener from an element. 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. Omit the fourth argument `opts` to use `false` or specify it based on the options used when the event listener was added.
```js ```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). 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()`. 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. 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. Invokes the provided callback on each animation frame.
Use recursion. Use recursion.
Provided that `running` is `true`, continue invoking `window.requestAnimationFrame()` which invokes the provided callback. 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. 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. Omit the second argument, `autoStart`, to implicitly call `start` when the function is invoked.
```js ```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. 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. Pass `{ behavior: 'smooth' }` to `.scrollIntoView` so it scrolls smoothly.
```js ```js
@ -4557,7 +4557,7 @@ minDate(array); // 2016-01-08T22:00:00.000Z
Results in a string representation of tomorrow's date. 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. Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.
```js ```js
@ -4735,6 +4735,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
const lengthIs4 = checkProp(l => l === 4, 'length'); const lengthIs4 = checkProp(l => l === 4, 'length');
lengthIs4([]); // false lengthIs4([]); // false
lengthIs4([1,2,3,4]); // true lengthIs4([1,2,3,4]); // true
@ -4975,11 +4976,11 @@ functionName(Math.max); // max (logged in debug channel of console)
### hz ### 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. `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. 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. 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. Omit the second argument, `iterations`, to use the default of 100 iterations.
```js ```js
@ -5333,7 +5334,7 @@ unfold(f, 10); // [-10, -20, -30, -40, -50]
### when ### 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`. 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). 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. 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. Omit the second argument to use the default `kFactor` of 32.
```js ```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. 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`. 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`. If the key exists in object, return target value, otherwise, return `null`.
```js ```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. 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`. Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
```js ```js
@ -7754,7 +7755,7 @@ const b = shallowClone(a); // a !== b
Get size of arrays, objects or strings. 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` property for arrays.
Use `length` or `size` value if available or number of keys for objects. 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. 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. 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). 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 ```js
@ -8991,7 +8992,7 @@ isNumber(NaN); // false
Returns a boolean determining if the passed value is an object or not. 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. 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 ```js

View File

@ -515,8 +515,8 @@
<ul> <ul>
<li><a href="https://30-seconds.github.io/30-seconds-of-css/">30 seconds of CSS</a></li> <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="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/30-seconds/30-seconds-of-python-code">30 seconds of Python</a></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-php-code">30 seconds of PHP</a></li>
</ul><br /> </ul><br />
<h2 class="category-name">Maintainers</h2> <h2 class="category-name">Maintainers</h2>
<div class="flex-row"> <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 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 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> <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'); const lengthIs4 = checkProp(l => l === 4, 'length');
lengthIs4([]); // false lengthIs4([]); // false
lengthIs4([1,2,3,4]); // true lengthIs4([1,2,3,4]); // true