JSPM

@writetome51/get-index-for-reversed-array

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q37790F
  • License MIT

Function receives array index and returns the new index that same item would have if the array's order were reversed

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.

Examples

let arr = ['a', 'b', 'c', 'd', 'e'];   
let index = arr.indexOf('d');
arr.reverse();
getIndexForReversedArray(index, arr.length);
   // -->  1

arr = [7, 2, 6, 9, 3, 10];
let index = arr.indexOf(2);
arr.reverse();
getIndexForReversedArray(index, arr.length);
   // -->  2

Installation

npm i @writetome51/get-index-for-reversed-array

Loading

import {getIndexForReversedArray} from '@writetome51/get-index-for-reversed-array';