1.0.3 • Published 2 years ago

nv-array-find-index-in-ordered v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

nv-array-find-index-in-ordered

  • find index+1 in a ordered array

install

  • npm install nv-array-find-index-in-ordered

usage

example

    var rand_int = require("nv-random-number").int32;
    var  arr = Array.from({length:1000000}).map(r=>rand_int(0,2**31));
    arr.sort();
    var v  = arr[1000000/2];


    const find = require("nv-array-find-index-in-ordered").find;

    const f0 = ()=> arr.findIndex(r=>r===v)+1;
    const f1 = ()=> find(arr,v);


    const test =require("nv-facutil-simple-test").sync;

    console.log(test(10000,f0));
    /*{ rounds: 10000, f: [Function: f0], costed: 35215.29962348938 }*/
    console.log(test(10000,f1));
    /*{ rounds: 10000, f: [Function: f1], costed: 4517.022989273071 }*/

API


    if [true,<index>]     index  is (real-index +1)
    if [false,<index>]    index  is for splice-at  

LICENSE

  • ISC
1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago