Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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
Appearance settings

An array is a collection of values, stored contiguously.

License

NotificationsYou must be signed in to change notification settings

nodef/extra-array

Repository files navigation

Anarray is a collection of values, stored contiguously.
📦Node.js,🌐Web,📜Files,📰Docs,📘Wiki.


This package includes comprehensive set of array functions with which you cangenerate an array,clone it, queryabout it, get non-negativeindices, manage itslength,get/set elements, fully or partiallysort it, obtainminimum(s)/maximum(s),compare it with anotherarray, get apart of it,search a value, obtain all possiblearrangements orrandom arrangements,find an element,take/dropelements orscan from its beginning or its end,search the index of apart of it, performfunctional operations,flatten multi-level arrays,obtainprefix sum,manipulate it in various ways,count/partitionelements,split it,concatenate/join multiple arrays,rearrangeelements within it, or performingset 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 asrangedPartialSort(). Functions likeswap() are pure and do notmodify the array itself, while functions likeswap$()do modify (update) thearray itself. Some functions accept a map function forfaster comparison, suchasunique(). Further, functions which return an iterable instead of an arrayare prefixed withi, such asisubsequences(). We borrow some names fromother programming languages 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_array global variable after loading with a<script> tagfrom thejsDelivr CDN.

Stability:Experimental.

NOTE: The use of negative indices in certain functions such asslice() isprovided as a convenience for access elements from the end of the array.However, negative indices can be thought of as referring to a virtual mirroredversion of the original array, which can be counter-intuitive and make itharder to reason about the behavior of functions that use them. We are workingon a solution to this problem. Any suggestions are welcome.


constxarray=require('extra-array');// import * as xarray from "extra-array";// import * as xarray from "https://unpkg.com/extra-array/index.mjs"; (deno)varx=[1,2,3];xarray.get(x,-1);// → 3varx=[1,2,3,4];xarray.swap(x,0,1);// → [ 2, 1, 3, 4 ]varx=[1,2,3,4];xarray.rotate(x,1);// → [ 2, 3, 4, 1 ]xarray.permutations([1,2,3]);// → [//   [],          [ 1 ],//   [ 2 ],       [ 3 ],//   [ 1, 2 ],    [ 1, 3 ],//   [ 2, 1 ],    [ 2, 3 ],//   [ 3, 1 ],    [ 3, 2 ],//   [ 1, 2, 3 ], [ 1, 3, 2 ],//   [ 2, 1, 3 ], [ 2, 3, 1 ],//   [ 3, 1, 2 ], [ 3, 2, 1 ]// ]


Index

PropertyDescription
fromRangeGenerate array from given number range.
fromInvocationGenerate array from repeated function invocation.
fromApplicationGenerate array from repeated function application.
fromIterableConvert an iterable to array.
fromIterable$Convert an iterable to array!
shallowCloneShallow clone an array.
deepCloneDeep clone an array.
isCheck if value is an array.
keysObtain all indices.
valuesGet all values.
entriesObtain all index-value pairs.
indexGet zero-based index for an element in array.
indexRangeGet zero-based index range for part of array.
isEmptyCheck if an array is empty.
lengthFind the length of an array.
resize$Resize an array to given length!
clear$Remove all elements from an array!
getGet value at index.
getAllGet values at indices.
getPathGet value at path in a nested array.
hasPathCheck if nested array has a path.
setSet value at index.
set$Set value at index!
setPath$Set value at path in a nested array!
swapExchange two values.
swap$Exchange two values!
swapRangesExchange two ranges of values.
swapRanges$Exchange two ranges of values!
removeRemove value at index.
remove$Remove value at index!
removePath$Remove value at path in a nested array!
isSortedExamine if array is sorted.
hasUnsortedValueExamine if array has an unsorted value.
searchUnsortedValueFind first index of an unsorted value.
sortArrange values in order.
sort$Arrange values in order!
partialSortPartially arrange values in order.
partialSort$Partially arrange values in order!
minimumFind first smallest value.
minimumEntryFind first smallest entry.
maximumFind first largest value.
maximumEntryFind first largest entry.
rangeFind smallest and largest values.
rangeEntriesFind smallest and largest entries.
minimumsFind smallest values.
minimumEntriesFind smallest entries.
maximumsFind largest values.
maximumEntriesFind largest entries.
searchMinimumValueFind first index of minimum value.
searchMaximumValueFind first index of maximum value.
searchMinimumValuesFind indices of minimum values.
searchMaximumValuesFind indices of maximum values.
isEqualExamine if two arrays are equal.
compareCompare two arrays (lexicographically).
headGet first value.
tailGet values except first.
initGet values except last.
lastGet last value.
middleGet values from middle.
sliceGet part of an array.
slice$Get part of an array!
includesCheck if array has a value.
hasValueExamine if array has a value.
searchValueFind first index of a value.
searchValueRightFind last index of a value.
searchValueAllFind indices of value.
searchAdjacentDuplicateValueFind first index of an adjacent duplicate value.
searchMismatchedValueFind first index where two arrays differ.
hasPrefixExamine if array starts with a prefix.
hasSuffixExamine if array ends with a suffix.
hasInfixExamine if array contains an infix.
hasSubsequenceExamine if array has a subsequence.
hasPermutationExamine if array has a permutation.
prefixesObtain all possible prefixes.
suffixesObtain all possible suffixes.
infixesObtain all possible infixes.
subsequencesObtain all possible subsequences.
permutationsObtain all possible permutations.
searchInfixFind first index of an infix.
searchInfixRightFind last index of an infix.
searchInfixAllFind indices of an infix.
searchSubsequenceFind first index of a subsequence.
randomValuePick an arbitrary value.
randomPrefixPick an arbitrary prefix.
randomSuffixPick an arbitrary suffix.
randomInfixPick an arbitrary infix.
randomSubsequencePick an arbitrary subsequence.
randomPermutationPick an arbitrary permutation.
randomPermutation$Pick an arbitrary permutation!
findFind first value passing a test.
findRightFind last value passing a test.
takeKeep first n values only.
takeRightKeep last n values only.
takeWhileKeep values from left, while a test passes.
takeWhileRightKeep values from right, while a test passes.
dropDiscard first n values only.
dropRightDiscard last n values only.
dropWhileDiscard values from left, while a test passes.
dropWhileRightDiscard values from right, while a test passes.
scanWhileScan from left, while a test passes.
scanWhileRightScan from right, while a test passes.
scanUntilScan from left, until a test passes.
scanUntilRightScan from right, until a test passes.
indexOfFind first index of a value.
lastIndexOfFind last index of a value.
searchFind index of first value passing a test.
searchRightFind index of last value passing a test.
searchAllFind indices of values passing a test.
forEachCall a function for each value.
someExamine if any value satisfies a test.
everyExamine if all values satisfy a test.
mapTransform values of an array.
map$Transform values of an array!
reduceReduce values of array to a single value.
reduceRightReduce values from right, to a single value.
filterKeep values which pass a test.
filter$Keep values which pass a test!
filterAtKeep values at given indices.
rejectDiscard values which pass a test.
reject$Discard values which pass a test!
rejectAtDiscard values at given indices.
flatFlatten nested array to given depth.
flatMapFlatten nested array, based on map function.
exclusiveScanPerform exclusive prefix scan from left to right.
exclusiveScan$Perform exclusive prefix scan from left to right!
inclusiveScanPerform inclusive prefix scan from left to right.
inclusiveScan$Perform inclusive prefix scan from left to right!
adjacentCombineCombine adjacent values of an array.
adjacentCombine$Combine adjacent values of an array!
interspersePlace a separator between every value.
interpolateEstimate new values between existing ones.
intermixPlace values of an array between another.
interleavePlace values from iterables alternately.
zipCombine values from arrays.
fillFill with given value.
fill$Fill with given value!
pushAdd value to the end.
push$Add values to the end!
popRemove last value.
pop$Remove last value!
shiftRemove first value.
shift$Remove first value!
unshiftAdd values to the start.
unshift$Add values to the start!
copyCopy part of array to another.
copy$Copy part of array to another!
copyWithinCopy part of array within.
copyWithin$Copy part of array within!
moveWithinMove part of array within.
moveWithin$Move part of array within!
spliceRemove or replace existing values.
splice$Remove or replace existing values!
countCount values which satisfy a test.
countEachCount occurrences of each distinct value.
partitionSegregate values by test result.
partitionEachSegregate each distinct value.
splitBreak array considering test as separator.
splitAtBreak array considering indices as separator.
cutBreak array when test passes.
cutRightBreak array after test passes.
cutAtBreak array at given indices.
cutAtRightBreak array after given indices.
groupKeep similar values together and in order.
chunkBreak array into chunks of given size.
concatAppend values from arrays.
concat$Append values from arrays!
joinJoin values together into a string.
cycleObtain values that cycle through array.
repeatRepeat an array given times.
reverseReverse the values.
reverse$Reverse the values!
rotateRotate values in array.
rotate$Rotate values in array!
isUniqueExamine if there are no duplicate values.
isDisjointExamine if arrays have no value in common.
uniqueRemove duplicate values.
unionObtain values present in any array.
union$Obtain values present in any array!
intersectionObtain values present in both arrays.
differenceObtain values not present in another array.
symmetricDifferenceObtain values not present in both arrays.
cartesianProductObtain cartesian product of arrays.


References




ORGDOICoverage StatusTest Coverage


[8]ページ先頭

©2009-2025 Movatter.jp