Travis build: 740 [ci skip]
This commit is contained in:
34
README.md
34
README.md
@ -265,6 +265,15 @@
|
||||
|
||||
</details>
|
||||
|
||||
### _Uncategorized_
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
|
||||
* [`sortedIndex`](#sortedindex)
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
## 🔌 Adapter
|
||||
|
||||
@ -4515,6 +4524,31 @@ yesNo('Foo', true); // true
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
---
|
||||
## _Uncategorized_
|
||||
|
||||
### sortedIndex
|
||||
|
||||
Returns the lowest index at which value should be inserted into array in order to maintain its sort order.
|
||||
|
||||
Check if the array is sorted in descending order (loosely).
|
||||
Use `Array.findIndex()` to find the appropriate index where the element should be inserted.
|
||||
|
||||
```js
|
||||
const sortedIndex = (arr, n) => {
|
||||
const isDescending = arr[0] > arr[arr.length - 1];
|
||||
const index = arr.findIndex(el => (isDescending ? n >= el : n <= el));
|
||||
return index === -1 ? arr.length : index;
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
sortedIndex([5, 3, 2, 1], 4); // 1
|
||||
sortedIndex([30, 50], 40); // 1
|
||||
```
|
||||
|
||||
<br>[⬆ back to top](#table-of-contents)
|
||||
|
||||
|
||||
## Collaborators
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -8,12 +8,12 @@ Use `Array.findIndex()` to find the appropriate index where the element should b
|
||||
```js
|
||||
const sortedIndex = (arr, n) => {
|
||||
const isDescending = arr[0] > arr[arr.length - 1];
|
||||
const index = arr.findIndex(el => isDescending ? n >= el : n <= el);
|
||||
const index = arr.findIndex(el => (isDescending ? n >= el : n <= el));
|
||||
return index === -1 ? arr.length : index;
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
sortedIndex([5,3,2,1], 4); // 1
|
||||
sortedIndex([30,50],40); // 1
|
||||
sortedIndex([5, 3, 2, 1], 4); // 1
|
||||
sortedIndex([30, 50], 40); // 1
|
||||
```
|
||||
|
||||
@ -130,6 +130,7 @@ similarity:array
|
||||
size:object
|
||||
sleep:function
|
||||
sortCharactersInString:string
|
||||
sortedIndex:uncategorized
|
||||
speechSynthesis:browser
|
||||
splitLines:string
|
||||
spreadOver:adapter
|
||||
|
||||
Reference in New Issue
Block a user