insertion-index
v1.0.0
Published
Get insertion index for item in array
Downloads
2
Readme
insertion-index
Get insertion index for item in array.
Installation
npm install --save insertion-index
Usage
const insertionIndex = require('insertion-index');
const array = [1, 2, 3, 5];
const item = 4;
const compareNb = (i, j) => i < j;
const index = insertionIndex(array, item, compareNb);
// => 3
array.splice(index, 0, item);
// => [1, 2, 3, 4, 5]
Thanks
All thanks goes to @Izhaki for his gist itself based on @primaryobjects's one.