|
1 |
| -A sorted array is a collection of values, arranged in an order. |
| 1 | +A [sorted array] is a collection of values, arranged in an order.<br> |
| 2 | +📦 [Node.js](https://www.npmjs.com/package/extra-sorted-array), |
| 3 | +🌐 [Web](https://www.npmjs.com/package/extra-sorted-array.web), |
| 4 | +📜 [Files](https://unpkg.com/extra-sorted-array/), |
| 5 | +📰 [Docs](https://nodef.github.io/extra-sorted-array/), |
| 6 | +📘 [Wiki](https://github.com/nodef/extra-sorted-array/wiki/). |
2 | 7 |
|
| 8 | + |
3 | 9 |
|
| 10 | +<br> |
| 11 | + |
| 12 | + |
| 13 | +This package includes comprehensive set of functions that operate on a sorted |
| 14 | +array with which you can **search a value** using binary search, **merge** |
| 15 | +multiple sorted arrays, or perform **set operations** upon it. |
| 16 | + |
| 17 | +We use a consistent naming scheme that helps you quickly identify the functions |
| 18 | +you need. All functions except `from*()` take array as 1st parameter. Some |
| 19 | +functions operate on a specified range in the array and are called `ranged*()`, |
| 20 | +such as `rangedMerge()`. Functions like `slice()` are pure and do not modify the |
| 21 | +array itself, while functions like `slice$()` *do modify (update)* the array |
| 22 | +itself. Some functions accept a map function in addition to a compare function. |
| 23 | +Further, functions which return an iterable instead of an array are prefixed |
| 24 | +with `i`, such as `isubsequences()`. We borrow some names from other programming |
| 25 | +languages such as *Haskell*, *Python*, *Java*, and *Processing*. |
| 26 | + |
| 27 | +With this package, you can simplify the implementation of complex algorithms, |
| 28 | +and be able to achieve your goals faster, regardless of your level of expertise. |
| 29 | +Try it out today and discover how it can transform your development experience! |
| 30 | +This package is available in *Node.js* and *Web* formats. To use it on the web, |
| 31 | +simply use the `extra_sorted_array` global variable after loading with a |
| 32 | +`<script>` tag from the [jsDelivr CDN]. |
| 33 | + |
| 34 | +> Stability: [Experimental](https://www.youtube.com/watch?v=L1j93RnIxEo). |
| 35 | +
|
| 36 | +[sorted array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort |
| 37 | +[jsDelivr CDN]: https://cdn.jsdelivr.net/npm/extra-sorted-array.web/index.js |
| 38 | + |
| 39 | +<br> |
| 40 | + |
| 41 | +```javascript |
| 42 | +const xsortedArray = require('extra-sorted-array'); |
| 43 | +// import * as xsortedArray from "extra-sorted-array"; |
| 44 | +// import * as xsortedArray from "https://unpkg.com/extra-sorted-array/index.mjs"; (deno) |
| 45 | + |
| 46 | +var x = [10, 20, 20, 40, 40, 80]; |
| 47 | +xsortedArray.searchValue(x, 40); |
| 48 | +// → 3 |
| 49 | + |
| 50 | +var x = [10, 20, 20, 40, 40, 80]; |
| 51 | +var y = [20, 50, 70]; |
| 52 | +xsortedArray.merge(x, y); |
| 53 | +// → [ 10, 20, 20, 20, 40, 40, 50, 70, 80 ] |
| 54 | + |
| 55 | +var x = [10, 20, 20, 40, 40, 80]; |
| 56 | +var y = [20, 50, 70]; |
| 57 | +var z = [30, 60, 90]; |
| 58 | +xsortedArray.mergeAll([x, y, z]); |
| 59 | +// → [ 10, 20, 20, 20, 30, 40, 40, 50, 60, 70, 80, 90 ] |
| 60 | + |
| 61 | +var x = [10, 20, 20, 40, 40, 80]; |
| 62 | +var y = [20, 50, 70]; |
| 63 | +xsortedArray.isDisjoint(x, y); |
| 64 | +// → false |
| 65 | + |
| 66 | +var x = [10, 20, 20, 40, 40, 80]; |
| 67 | +var y = [20, 50, 80]; |
| 68 | +xsortedArray.intersection(x, y); |
| 69 | +// → [ 20, 80 ] |
| 70 | +``` |
| 71 | + |
| 72 | +<br> |
| 73 | +<br> |
| 74 | + |
| 75 | + |
| 76 | +## Index |
| 77 | + |
| 78 | +| Property | Description | |
| 79 | +| ---- | ---- | |
| 80 | +| [includes] | Check if sorted array has a value using binary search. | |
| 81 | +| [hasValue] | Check if sorted array has a value using binary search. | |
| 82 | +| [indexOf] | Find first index of value using binary search. | |
| 83 | +| [lastIndexOf] | Find last index of value using binary search. | |
| 84 | +| [searchValue] | Find first index of value using binary search. | |
| 85 | +| [searchValueRight] | Find last index of a value using binary search. | |
| 86 | +| [searchValueAny] | Find any index of a value using binary search. | |
| 87 | +| [searchClosestValue] | Find index of closest value using binary search. | |
| 88 | +| | | |
| 89 | +| [merge] | Merge values from two sorted arrays. | |
| 90 | +| [rangedMerge] | Merge ranges of values from two sorted arrays. | |
| 91 | +| [mergeAll] | Merge values from sorted arrays. | |
| 92 | +| | | |
| 93 | +| [isUnique] | Examine if there are no duplicate values. | |
| 94 | +| [isDisjoint] | Examine if arrays have no value in common. | |
| 95 | +| [unique] | Remove duplicate values. | |
| 96 | +| [union] | Obtain values present in any sorted array. | |
| 97 | +| [intersection] | Obtain values present in both sorted arrays. | |
| 98 | +| [difference] | Obtain values not present in another sorted array. | |
| 99 | +| [symmetricDifference] | Obtain values present in either sorted array but not both. | |
| 100 | + |
| 101 | + |
| 102 | +<br> |
| 103 | +<br> |
| 104 | + |
| 105 | + |
| 106 | +## References |
| 107 | + |
| 108 | +- [binary-sorted-array - npm : Michal Iwanow](https://www.npmjs.com/package/binary-sorted-array) |
| 109 | +- [How to add region in java script file, visual studio](https://stackoverflow.com/a/51550649/1413259) |
| 110 | + |
| 111 | +<br> |
| 112 | +<br> |
| 113 | + |
| 114 | + |
| 115 | +[](https://www.youtube.com/watch?v=VYOOiIJeBOA)<br> |
| 116 | +[](https://nodef.github.io) |
| 117 | +[](https://coveralls.io/github/nodef/extra-sorted-array?branch=master) |
4 | 118 | [](https://codeclimate.com/github/nodef/extra-sorted-array/test_coverage)
|
| 119 | +<!-- [](https://zenodo.org/badge/latestdoi/133759104) --> |
| 120 | + |
| 121 | + |
| 122 | +[includes]: https://github.com/nodef/extra-sorted-array/wiki/includes |
| 123 | +[hasValue]: https://github.com/nodef/extra-sorted-array/wiki/hasValue |
| 124 | +[indexOf]: https://github.com/nodef/extra-sorted-array/wiki/indexOf |
| 125 | +[lastIndexOf]: https://github.com/nodef/extra-sorted-array/wiki/lastIndexOf |
| 126 | +[searchValue]: https://github.com/nodef/extra-sorted-array/wiki/searchValue |
| 127 | +[searchValueRight]: https://github.com/nodef/extra-sorted-array/wiki/searchValueRight |
| 128 | +[searchValueAny]: https://github.com/nodef/extra-sorted-array/wiki/searchValueAny |
| 129 | +[searchClosestValue]: https://github.com/nodef/extra-sorted-array/wiki/searchClosestValue |
| 130 | +[merge]: https://github.com/nodef/extra-sorted-array/wiki/merge |
| 131 | +[rangedMerge]: https://github.com/nodef/extra-sorted-array/wiki/rangedMerge |
| 132 | +[mergeAll]: https://github.com/nodef/extra-sorted-array/wiki/mergeAll |
| 133 | +[isUnique]: https://github.com/nodef/extra-sorted-array/wiki/isUnique |
| 134 | +[isDisjoint]: https://github.com/nodef/extra-sorted-array/wiki/isDisjoint |
| 135 | +[unique]: https://github.com/nodef/extra-sorted-array/wiki/unique |
| 136 | +[union]: https://github.com/nodef/extra-sorted-array/wiki/union |
| 137 | +[intersection]: https://github.com/nodef/extra-sorted-array/wiki/intersection |
| 138 | +[difference]: https://github.com/nodef/extra-sorted-array/wiki/difference |
| 139 | +[symmetricDifference]: https://github.com/nodef/extra-sorted-array/wiki/symmetricDifference |
0 commit comments