Travis build: 1057
This commit is contained in:
34
README.md
34
README.md
@ -342,6 +342,15 @@ average(1, 2, 3);
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
### _Uncategorized_
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>View contents</summary>
|
||||||
|
|
||||||
|
* [`indexOfAll`](#indexofall)
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
---
|
---
|
||||||
## 🔌 Adapter
|
## 🔌 Adapter
|
||||||
|
|
||||||
@ -5130,6 +5139,31 @@ yesNo('Foo', true); // true
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
---
|
||||||
|
## _Uncategorized_
|
||||||
|
|
||||||
|
### indexOfAll
|
||||||
|
|
||||||
|
Returns all indices of `val` in an array. If `val` never occurs, returns `[-1]`.
|
||||||
|
|
||||||
|
Use `Array.forEach()` to loop over elements and `Array.push()` to store indices for matching elements.
|
||||||
|
Return `[-1]` if `length` of the array of indices is `0`, otherwise return the array of indices.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const indexOfAll = (arr, val) => {
|
||||||
|
const indices = [];
|
||||||
|
arr.forEach((el, i) => el === val && indices.push(i));
|
||||||
|
return indices.length ? indices : [-1];
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
indexOfAll([1, 2, 3, 1, 2, 3], 1); // [0,3]
|
||||||
|
indexOfAll([1, 2, 3], 4); // [-1]
|
||||||
|
```
|
||||||
|
|
||||||
|
<br>[⬆ back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
## Collaborators
|
## Collaborators
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -5,16 +5,15 @@ Returns all indices of `val` in an array. If `val` never occurs, returns `[-1]`.
|
|||||||
Use `Array.forEach()` to loop over elements and `Array.push()` to store indices for matching elements.
|
Use `Array.forEach()` to loop over elements and `Array.push()` to store indices for matching elements.
|
||||||
Return `[-1]` if `length` of the array of indices is `0`, otherwise return the array of indices.
|
Return `[-1]` if `length` of the array of indices is `0`, otherwise return the array of indices.
|
||||||
|
|
||||||
``` js
|
```js
|
||||||
const indexOfAll = (arr, val) => {
|
const indexOfAll = (arr, val) => {
|
||||||
const indices = [];
|
const indices = [];
|
||||||
arr.forEach((el, i) => el === val && indices.push(i))
|
arr.forEach((el, i) => el === val && indices.push(i));
|
||||||
return indices.length ? indices : [-1];
|
return indices.length ? indices : [-1];
|
||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
``` js
|
```js
|
||||||
indexOfAll([1,2,3,1,2,3],1); // [0,3]
|
indexOfAll([1, 2, 3, 1, 2, 3], 1); // [0,3]
|
||||||
indexOfAll([1,2,3],4); // [-1]
|
indexOfAll([1, 2, 3], 4); // [-1]
|
||||||
```
|
```
|
||||||
|
|||||||
@ -62,6 +62,7 @@ head:array
|
|||||||
hexToRGB:utility,string,math,advanced
|
hexToRGB:utility,string,math,advanced
|
||||||
hide:browser,css
|
hide:browser,css
|
||||||
httpsRedirect:browser,url
|
httpsRedirect:browser,url
|
||||||
|
indexOfAll:uncategorized
|
||||||
initial:array
|
initial:array
|
||||||
initialize2DArray:array
|
initialize2DArray:array
|
||||||
initializeArrayWithRange:array,math
|
initializeArrayWithRange:array,math
|
||||||
|
|||||||
Reference in New Issue
Block a user