Formatting changes
This commit is contained in:
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
⚠️ **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. Only works as a result of user action (i.e. inside a `click` event listener).
|
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.
|
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).
|
||||||
|
|||||||
@ -9,5 +9,5 @@ const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexO
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
filterNonUnique([1, 2, 2, 3, 4, 4, 5]); // [1,3,5]
|
filterNonUnique([1, 2, 2, 3, 4, 4, 5]); // [1, 3, 5]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
### findLastKey
|
### findLastKey
|
||||||
|
|
||||||
Returns the last key that satisfies the provided testing function. Otherwise `undefined` is returned.
|
Returns the last key that satisfies the provided testing function.
|
||||||
|
Otherwise `undefined` is returned.
|
||||||
|
|
||||||
Use `Object.keys(obj)` to get all the properties of the object, `Array.reverse()` to reverse their order and `Array.find()` to test the provided function for each key-value pair. The callback receives three arguments - the value, the key and the object.
|
Use `Object.keys(obj)` to get all the properties of the object, `Array.reverse()` to reverse their order and `Array.find()` to test the provided function for each key-value pair.
|
||||||
|
The callback receives three arguments - the value, the key and the object.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const findLastKey = (obj, fn) =>
|
const findLastKey = (obj, fn) =>
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
### indexOfAll
|
### indexOfAll
|
||||||
|
|
||||||
Returns all indices of `val` in an array. If `val` never occurs, returns `[]`.
|
Returns all indices of `val` in an array.
|
||||||
|
If `val` never occurs, returns `[]`.
|
||||||
|
|
||||||
Use `Array.reduce()` to loop over elements and store indices for matching elements.
|
Use `Array.reduce()` to loop over elements and store indices for matching elements.
|
||||||
Return the array of indices.
|
Return the array of indices.
|
||||||
|
|||||||
@ -10,5 +10,5 @@ const initializeArrayWithValues = (n, val = 0) => Array(n).fill(val);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
initializeArrayWithValues(5, 2); // [2,2,2,2,2]
|
initializeArrayWithValues(5, 2); // [2, 2, 2, 2, 2]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -12,5 +12,5 @@ const intersection = (a, b) => {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
intersection([1, 2, 3], [4, 3, 2]); // [2,3]
|
intersection([1, 2, 3], [4, 3, 2]); // [2, 3]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
### join
|
### join
|
||||||
|
|
||||||
Joins all elements of an array into a string and returns this string. Uses a separator and an end separator.
|
Joins all elements of an array into a string and returns this string.
|
||||||
|
Uses a separator and an end separator.
|
||||||
|
|
||||||
Use `Array.reduce()` to combine elements into a string.
|
Use `Array.reduce()` to combine elements into a string.
|
||||||
Omit the second argument, `separator`, to use a default separator of `','`.
|
Omit the second argument, `separator`, to use a default separator of `','`.
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
### maxN
|
### maxN
|
||||||
|
|
||||||
Returns the `n` maximum elements from the provided array. If `n` is greater than or equal to the provided array's length, then return the original array(sorted in descending order).
|
Returns the `n` maximum elements from the provided array.
|
||||||
|
If `n` is greater than or equal to the provided array's length, then return the original array (sorted in descending order).
|
||||||
|
|
||||||
Use `Array.sort()` combined with the spread operator (`...`) to create a shallow clone of the array and sort it in descending order.
|
Use `Array.sort()` combined with the spread operator (`...`) to create a shallow clone of the array and sort it in descending order.
|
||||||
Use `Array.slice()` to get the specified number of elements.
|
Use `Array.slice()` to get the specified number of elements.
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
### minN
|
### minN
|
||||||
|
|
||||||
Returns the `n` minimum elements from the provided array. If `n` is greater than or equal to the provided array's length, then return the original array(sorted in ascending order).
|
Returns the `n` minimum elements from the provided array.
|
||||||
|
If `n` is greater than or equal to the provided array's length, then return the original array (sorted in ascending order).
|
||||||
|
|
||||||
Use `Array.sort()` combined with the spread operator (`...`) to create a shallow clone of the array and sort it in ascending order.
|
Use `Array.sort()` combined with the spread operator (`...`) to create a shallow clone of the array and sort it in ascending order.
|
||||||
Use `Array.slice()` to get the specified number of elements.
|
Use `Array.slice()` to get the specified number of elements.
|
||||||
|
|||||||
@ -9,5 +9,5 @@ const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
objectToPairs({ a: 1, b: 2 }); // [['a',1],['b',2]]
|
objectToPairs({ a: 1, b: 2 }); // [ ['a', 1], ['b', 2] ]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -9,5 +9,5 @@ const powerset = arr => arr.reduce((a, v) => a.concat(a.map(r => [v].concat(r)))
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
powerset([1, 2]); // [[], [1], [2], [2,1]]
|
powerset([1, 2]); // [[], [1], [2], [2, 1]]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -17,5 +17,5 @@ const shuffle = ([...arr]) => {
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const foo = [1, 2, 3];
|
const foo = [1, 2, 3];
|
||||||
shuffle(foo); // [2,3,1], foo = [1,2,3]
|
shuffle(foo); // [2, 3, 1], foo = [1, 2, 3]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -9,5 +9,5 @@ const similarity = (arr, values) => arr.filter(v => values.includes(v));
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
similarity([1, 2, 3], [1, 2, 4]); // [1,2]
|
similarity([1, 2, 3], [1, 2, 4]); // [1, 2]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -9,5 +9,5 @@ const uniqueElements = arr => [...new Set(arr)];
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5]
|
uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1, 2, 3, 4, 5]
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user