Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zoubin/indexes-of-sorted
return all the indexes in a sorted array
https://github.com/zoubin/indexes-of-sorted
Last synced: 8 days ago
JSON representation
return all the indexes in a sorted array
- Host: GitHub
- URL: https://github.com/zoubin/indexes-of-sorted
- Owner: zoubin
- Created: 2015-09-02T17:56:52.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-02T19:46:59.000Z (about 9 years ago)
- Last Synced: 2024-10-31T17:19:12.570Z (18 days ago)
- Language: JavaScript
- Size: 137 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# indexes-of-sorted
return range of the indexes in a sorted array## Example
```javascript
var indexesOfSorted = require('indexes-of-sorted');console.log(
indexesOfSorted(
[1, 1, 2, 2, 3, 3],
2
)
);
// [2, 4]console.log(
indexesOfSorted(
['AA', 'AA', 'aa', 'aa', 'ab', 'ab'],
'aa'
)
);
// [2, 4]console.log(
indexesOfSorted(
[{ x: 1 }, { x: 1 }, { x: 2 }, { x: 2 }, { x: 3 }, { x: 3 }],
{ x: 3 },
function cmp(a, b) {
return a.x - b.x;
}
)
);
// [4, 6]```
## indexesOfSorted(sorted, value, cmp)
### sorted
Type: `Array`
Either ascending or non-ascending.
Elements should be the same type, `String`, `Number`, or `Object`.
If `Object`, `cmp` should be specified
### value
Type: `mixed`
Should be the same type with elements in `sorted`.
### cmp
Type: `Function`
It specifies the way to compare,
like the callback passed to `Array.prototype.sort`.