Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A sorted array is a collection of values, arranged in an order.

License

NotificationsYou must be signed in to change notification settings

nodef/extra-sorted-array

Repository files navigation

Asorted array is a collection of values, arranged in an order.
📦Node.js,🌐Web,📜Files,📰Docs,📘Wiki.


This package includes comprehensive set of functions that operate on a sortedarray with which you cansearch a value using binary search,mergemultiple sorted arrays, or performset operations upon it.

We use a consistent naming scheme that helps you quickly identify the functionsyou need. All functions exceptfrom*() take array as 1st parameter. Somefunctions operate on a specified range in the array and are calledranged*(),such asrangedMerge(). Functions likeslice() are pure and do not modify thearray itself, while functions likeslice$()do modify (update) the arrayitself. Some functions accept a map function in addition to a compare function.Further, functions which return an iterable instead of an array are prefixedwithi, such asisubsequences(). We borrow some names from other programminglanguages such asHaskell,Python,Java, andProcessing.

With this package, you can simplify the implementation of complex algorithms,and be able to achieve your goals faster, regardless of your level of expertise.Try it out today and discover how it can transform your development experience!This package is available inNode.js andWeb formats. To use it on the web,simply use theextra_sorted_array global variable after loading with a<script> tag from thejsDelivr CDN.

Stability:Experimental.


constxsortedArray=require('extra-sorted-array');// import * as xsortedArray from "extra-sorted-array";// import * as xsortedArray from "https://unpkg.com/extra-sorted-array/index.mjs"; (deno)varx=[10,20,20,40,40,80];xsortedArray.searchValue(x,40);// → 3varx=[10,20,20,40,40,80];vary=[20,50,70];xsortedArray.merge(x,y);// → [ 10, 20, 20, 20, 40, 40, 50, 70, 80 ]varx=[10,20,20,40,40,80];vary=[20,50,70];varz=[30,60,90];xsortedArray.mergeAll([x,y,z]);// → [ 10, 20, 20, 20, 30, 40, 40, 50, 60, 70, 80, 90 ]varx=[10,20,20,40,40,80];vary=[20,50,70];xsortedArray.isDisjoint(x,y);// → falsevarx=[10,20,20,40,40,80];vary=[20,50,80];xsortedArray.intersection(x,y);// → [ 20, 80 ]


Index

PropertyDescription
includesCheck if sorted array has a value using binary search.
hasValueCheck if sorted array has a value using binary search.
indexOfFind first index of value using binary search.
lastIndexOfFind last index of value using binary search.
searchValueFind first index of value using binary search.
searchValueRightFind last index of a value using binary search.
searchValueAnyFind any index of a value using binary search.
searchClosestValueFind index of closest value using binary search.
mergeMerge values from two sorted arrays.
mergeAllMerge values from sorted arrays.
isUniqueExamine if there are no duplicate values.
isDisjointExamine if arrays have no value in common.
uniqueRemove duplicate values.
unionObtain values present in any sorted array.
intersectionObtain values present in both sorted arrays.
differenceObtain values not present in another sorted array.
symmetricDifferenceObtain values present in either sorted array but not both.


References




ORGCoverage StatusTest Coverage


[8]ページ先頭

©2009-2025 Movatter.jp