Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

extra-array

Package Overview
Dependencies
Maintainers
0
Versions
856
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extra-array

An array is a collection of values, stored contiguously.

  • 4.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.4K
increased by60.21%
Maintainers
0
Weekly downloads
 
Created
Source

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


This package includes comprehensive set of array functions with which you can generate an array, clone it, query about it, get non-negative indices, manage its length, get/set elements, fully or partially sort it, obtain minimum(s)/maximum(s), compare it with another array, get a part of it, search a value, obtain all possible arrangements or random arrangements, find an element, take/drop elements or scan from its beginning or its end, search the index of a part of it, perform functional operations, flatten multi-level arrays, obtain prefix sum, manipulate it in various ways, count/partition elements, split it, concatenate/join multiple arrays, rearrange elements within it, or performing set operations upon it.

We use a consistent naming scheme that helps you quickly identify the functions you need. All functions except from*() take array as 1st parameter. Some functions operate on a specified range in the array and are called ranged*(), such as rangedPartialSort(). Functions like swap() are pure and do not modify the array itself, while functions like swap$() do modify (update) the array itself. Some functions accept a map function for faster comparison, such as unique(). Further, functions which return an iterable instead of an array are prefixed with i, such as isubsequences(). We borrow some names from other programming languages such as Haskell, Python, Java, and Processing.

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 in Node.js and Web formats. To use it on the web, simply use the extra_array global variable after loading with a <script> tag from the jsDelivr CDN.

Stability: Experimental.

NOTE: The use of negative indices in certain functions such as slice() is provided as a convenience for access elements from the end of the array. However, negative indices can be thought of as referring to a virtual mirrored version of the original array, which can be counter-intuitive and make it harder to reason about the behavior of functions that use them. We are working on a solution to this problem. Any suggestions are welcome.


const xarray = require('extra-array');
// import * as xarray from "extra-array";
// import * as xarray from "https://unpkg.com/extra-array/index.mjs"; (deno)

var x = [1, 2, 3];
xarray.get(x, -1);
// → 3

var x = [1, 2, 3, 4];
xarray.swap(x, 0, 1);
// → [ 2, 1, 3, 4 ]

var x = [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




ORG DOI Coverage Status Test Coverage

Keywords

FAQs

Package last updated on 29 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc