https://github.com/writetome51/get-reverse-index
Function receives an array index and returns the new index that same item would have if the array's order were reversed
https://github.com/writetome51/get-reverse-index
array index javascript reverse reversed translated typescript
Last synced: 6 months ago
JSON representation
Function receives an array index and returns the new index that same item would have if the array's order were reversed
- Host: GitHub
- URL: https://github.com/writetome51/get-reverse-index
- Owner: writetome51
- License: mit
- Created: 2019-03-22T23:11:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-05T22:48:44.000Z (over 5 years ago)
- Last Synced: 2025-05-28T11:18:07.462Z (7 months ago)
- Topics: array, index, javascript, reverse, reversed, translated, typescript
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# getReverseIndex(
index,
arrayLength
): number
Receives array `index` and returns the new index that same item would have
if the array's order were reversed.
## Examples
```js
let arr = ['a', 'b', 'c', 'd', 'e'];
let index = arr.indexOf('d');
getReverseIndex(index, arr.length);
// --> 1
arr = [7, 2, 6, 9, 3, 10];
index = arr.indexOf(2);
getReverseIndex(index, arr.length);
// --> 4
```
## Installation
`npm i @writetome51/get-reverse-index`
## Loading
``` js
import {getReverseIndex} from '@writetome51/get-reverse-index';
```