Travis build: 539
This commit is contained in:
33
README.md
33
README.md
@ -168,6 +168,7 @@ average(1, 2, 3);
|
|||||||
* [`remove`](#remove)
|
* [`remove`](#remove)
|
||||||
* [`sample`](#sample)
|
* [`sample`](#sample)
|
||||||
* [`sampleSize`](#samplesize)
|
* [`sampleSize`](#samplesize)
|
||||||
|
* [`shank`](#shank)
|
||||||
* [`shuffle`](#shuffle)
|
* [`shuffle`](#shuffle)
|
||||||
* [`similarity`](#similarity)
|
* [`similarity`](#similarity)
|
||||||
* [`sortedIndex`](#sortedindex)
|
* [`sortedIndex`](#sortedindex)
|
||||||
@ -2353,6 +2354,38 @@ sampleSize([1, 2, 3], 2); // [3,1]
|
|||||||
sampleSize([1, 2, 3], 4); // [2,3,1]
|
sampleSize([1, 2, 3], 4); // [2,3,1]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
### shank
|
||||||
|
|
||||||
|
Has the same functionality as [`Array.prototype.splice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice), but returning a new array instead of mutating the original array.
|
||||||
|
|
||||||
|
Use `Array.slice()` and `Array.concat()` to get a new array with the new contents after removing existing elements and/or adding new elements.
|
||||||
|
Omit the second argument, `index`, to start at `0`.
|
||||||
|
Omit the third argument, `delCount`, to remove `0` elements.
|
||||||
|
Omit the fourth argument, `elements`, in order to not add any new elements.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const shank = (arr, index = 0, delCount = 0, ...elements) =>
|
||||||
|
arr
|
||||||
|
.slice(0, index)
|
||||||
|
.concat(elements)
|
||||||
|
.concat(arr.slice(index + delCount));
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
const names = ['alpha', 'bravo', 'charlie'];
|
||||||
|
const namesAndDelta = shank(names, 1, 0, 'delta'); // [ 'alpha', 'delta', 'bravo', 'charlie' ]
|
||||||
|
const namesNoBravo = shank(names, 1, 1); // [ 'alpha', 'charlie' ]
|
||||||
|
console.log(names); // ['alpha', 'bravo', 'charlie']
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -9,7 +9,8 @@ Omit the fourth argument, `elements`, in order to not add any new elements.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const shank = (arr, index = 0, delCount = 0, ...elements) =>
|
const shank = (arr, index = 0, delCount = 0, ...elements) =>
|
||||||
arr.slice(0, index)
|
arr
|
||||||
|
.slice(0, index)
|
||||||
.concat(elements)
|
.concat(elements)
|
||||||
.concat(arr.slice(index + delCount));
|
.concat(arr.slice(index + delCount));
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user