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

    2.0.0 • Public • Published

    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';

    Install

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

    DownloadsWeekly Downloads

    8

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    3.2 kB

    Total Files

    4

    Last publish

    Collaborators

    • writetome51