Package Exports
- @writetome51/get-index-for-reversed-array
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@writetome51/get-index-for-reversed-array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
getIndexForReversedArray(
index,
arrayLength
): number
Receives array index and returns the new index that same item would have
if the array's order were reversed.
Example: you have this array: ['a', 'b', 'c', 'd', 'e'].
The index of 'd' is 3. Then you reverse the order of the array, and you
need the new index of 'd'. So you call:
getIndexForReversedArray(3, array.length); // the index of 'd' was 3.
// --> 1The new index is 1.
Further Example
arr = [7, 2, 6, 9, 3, 10];
let index = arr.indexOf(2);
arr.reverse();
index = getIndexForReversedArray(index, arr.length);
console.log(arr[index]); // console: '2'Installation
npm i @writetome51/get-index-for-reversed-array
Loading
// if using Typescript:
import {getIndexForReversedArray} from '@writetome51/get-index-for-reversed-array';
// if using ES5 Javascript:
var getIndexForReversedArray =
require('@writetome51/get-index-for-reversed-array').getIndexForReversedArray;