1.0.3 • Published 2 years ago
nv-array-find-index-in-ordered v1.0.3
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
- find(a:Array\<Ele>,v:Ele,cmp_func:(a,b)=>0|1|-1): boolean,\<js-array-index>
if [true,<index>] index is (real-index +1)
if [false,<index>] index is for splice-at
LICENSE
- ISC