Merge pull request #1046 from 30-seconds/fix-breaking-snippets

Fix breaking snippets
This commit is contained in:
Angelos Chalaris
2019-11-21 22:03:29 +02:00
committed by GitHub
4 changed files with 9 additions and 10 deletions

View File

@ -3,11 +3,11 @@ title: copyToClipboard
tags: browser,string,advanced tags: browser,string,advanced
--- ---
⚠️ **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).
⚠️ **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).
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.
Use `Selection.getRangeAt()`to store the selected range (if any). Use `Selection.getRangeAt()`to store the selected range (if any).
Use `document.execCommand('copy')` to copy to the clipboard. Use `document.execCommand('copy')` to copy to the clipboard.
@ -36,4 +36,4 @@ const copyToClipboard = str => {
```js ```js
copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard. copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard.
``` ```

View File

@ -8,7 +8,6 @@ Returns `true` if the target value exists in a JSON object, `false` otherwise.
Check if `keys` is non-empty and use `Array.prototype.every()` to sequentially check its keys to internal depth of the object, `obj`. Check if `keys` is non-empty and use `Array.prototype.every()` to sequentially check its keys to internal depth of the object, `obj`.
Use `Object.prototype.hasOwnProperty()` to check if `obj` does not have the current key or is not an object, stop propagation and return `false`. Use `Object.prototype.hasOwnProperty()` to check if `obj` does not have the current key or is not an object, stop propagation and return `false`.
Otherwise assign the key's value to `obj` to use on the next iteration. Otherwise assign the key's value to `obj` to use on the next iteration.
Return `false` beforehand if given key list is empty. Return `false` beforehand if given key list is empty.
```js ```js

View File

@ -3,10 +3,10 @@ title: permutations
tags: array,recursion,advanced tags: array,recursion,advanced
--- ---
⚠️ **WARNING**: This function's execution time increases exponentially with each array element. Anything more than 8 to 10 entries will cause your browser to hang as it tries to solve all the different combinations.
Generates all permutations of an array's elements (contains duplicates). Generates all permutations of an array's elements (contains duplicates).
⚠️ **WARNING**: This function's execution time increases exponentially with each array element. Anything more than 8 to 10 entries will cause your browser to hang as it tries to solve all the different combinations.
Use recursion. Use recursion.
For each element in the given array, create all the partial permutations for the rest of its elements. For each element in the given array, create all the partial permutations for the rest of its elements.
Use `Array.prototype.map()` to combine the element with each partial permutation, then `Array.prototype.reduce()` to combine all permutations in one array. Use `Array.prototype.map()` to combine the element with each partial permutation, then `Array.prototype.reduce()` to combine all permutations in one array.
@ -27,4 +27,4 @@ const permutations = arr => {
```js ```js
permutations([1, 33, 5]); // [ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ] permutations([1, 33, 5]); // [ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ]
``` ```

View File

@ -3,10 +3,10 @@ title: stringPermutations
tags: string,recursion,advanced tags: string,recursion,advanced
--- ---
⚠️ **WARNING**: This function's execution time increases exponentially with each character. Anything more than 8 to 10 characters will cause your browser to hang as it tries to solve all the different combinations.
Generates all permutations of a string (contains duplicates). Generates all permutations of a string (contains duplicates).
⚠️ **WARNING**: This function's execution time increases exponentially with each character. Anything more than 8 to 10 characters will cause your browser to hang as it tries to solve all the different combinations.
Use recursion. Use recursion.
For each letter in the given string, create all the partial permutations for the rest of its letters. For each letter in the given string, create all the partial permutations for the rest of its letters.
Use `Array.prototype.map()` to combine the letter with each partial permutation, then `Array.prototype.reduce()` to combine all permutations in one array. Use `Array.prototype.map()` to combine the letter with each partial permutation, then `Array.prototype.reduce()` to combine all permutations in one array.
@ -27,4 +27,4 @@ const stringPermutations = str => {
```js ```js
stringPermutations('abc'); // ['abc','acb','bac','bca','cab','cba'] stringPermutations('abc'); // ['abc','acb','bac','bca','cab','cba']
``` ```