Travis build: 1057

This commit is contained in:
30secondsofcode
2018-01-06 11:49:05 +00:00
parent b730243c96
commit 1009250bdb
4 changed files with 49 additions and 8 deletions

View File

@ -342,6 +342,15 @@ average(1, 2, 3);
</details>
### _Uncategorized_
<details>
<summary>View contents</summary>
* [`indexOfAll`](#indexofall)
</details>
---
## 🔌 Adapter
@ -5130,6 +5139,31 @@ yesNo('Foo', true); // true
<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