UNPKG

@extra-array/insert

Version:

Inserts a value to an ordered array.

29 lines (21 loc) 653 B
Inserts a value to an ordered array.<br> > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array ```javascript array.insert(x, v, [fn]); // x: an array // v: value to insert // fn: compare function (a, b) // --> x ``` ```javascript const array = require('extra-array'); var a = [1, 7, 8, 10]; array.insert(a, 5); // [1, 5, 7, 8, 10] var b = ['a', 'K', 'M', 'n']; array.insert(b, 'l', (a, b) => a.toLowerCase().localeCompare(b.toLowerCase())); // ['a', 'K', 'l', 'M', 'n']; ``` ### references - [Data.List.insert: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:insert)