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

extra-array

Package Overview
Dependencies
Maintainers
1
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.0.127
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
increased by118.01%
Maintainers
1
Weekly downloads
Ā 
Created
Source

An array is a collection of values, stored contiguously.
šŸ“¦ Node.js, šŸŒ Web, šŸ“œ Files, šŸ“° Docs, šŸ“˜ Wiki.

This package includes common array functions related to querying about arrays, generating them, comparing one with another, finding their length, getting and setting elements, obtaining its properties, getting a part of it, rearranging elements in it, finding an element of a subset of elements in it, performing functional operations, manipulating it in various ways, combining together arrays or its elements, of performing set operations upon it.

All functions except from*() take array as 1st parameter. Methods like swap() are pure and do not modify the array itself, while methods like swap$() do modify (update) the array itself. Some methods accept a map function for faster comparision (like unique). I find the map-approach beautiful, which I learned from Haskell's sortOn(). You can notice that I have followed Javascript naming scheme as far as possible. Some names are borrowed from Haskell, Python, Java, Processing.

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.


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);
// ā†’ [4, 1, 2, 3]

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.
ikeysList all indices.
ivaluesList all values.
ientriesList 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.
iprefixesList all possible prefixes.
isuffixesList all possible suffixes.
iinfixesList all possible infixes.
isubsequencesList all possible subsequences.
ipermutationsList 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.
accumulateProduce accumulating values.
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 07 May 2023

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