Array (package) - MrKaszeba19/PapajLang GitHub Wiki

Array is a package of functions for PapajScript. This package contains functions that manipulate arrays. It was released on May 15, 2020 along with the version 0.4.3.

The earliest known stable RPN Calculator version to work with String – 0.4.3.

List of Array functions

Note:

  • If you do not want to type Array. every time, just type @use(Array) before. However, if you want to stop using the package, type @unuse(Array).
  • The version 0.5.1.1 is the last version where you can use Array. functions without running @use(Array). Starting from April 16, 2021, all Array functions require to be activated by @use(Array)
  • The arrays are indexed starting from 0 by default, i.e. 0th element of Array means the "real-life" first one.

Currently supported functions

Package Function Syntax Output type Purpose Since
Array.between ARR1 NUM1 NUM2 function Array Return an array that has A1 value from indexes between N1 and N2 0.5.1
Array.crush ARR1 function set of Entity split an array to entities (with preserving the array) 0.5.1
Array.crushBy ARR1 NUM1 function set of Array split an array to subarrays of N1 size (with preserving the main array) 0.5.1
Array.cut ARR1 EXP1 function Array Return an array with ARR1's elements that do not meet the EXP1 condition 0.5.2
Array.cutLeft ARR1 NUM1 function Array Return an array that has cut the first N1 elements of A1 array 0.5.1
Array.cutRight ARR1 NUM1 function Array Return an array that has cut the last N1 elements of A1 array 0.5.1
Array.cutBothSides ARR1 NUM1 NUM2 function Array Return an array that has cut the first N1 and the last N2 elements of A1 array 0.5.1
Array.cutNulls ARR1 function Array Remove all NULL elements from A1 0.5.2
Array.cutEmptyStrings ARR1 function Array Remove all empty string elements from A1 0.5.2
Array.cutZeros ARR1 function Array Remove all zero-valued numbers from A1 0.5.2
Array.destroy ARR1 function set of Entity remove the array and return its entities 0.5.1
Array.distinct ARR1 function Array Get an array with A1's distinct elements 0.5.2
Array.distinctNumbers ARR1 function Array Get an array with A1's elements having distinct numerical values 0.5.2
Array.distinctStrings ARR1 function Array Get an array with A1's elements having distinct string values 0.5.2
Array.filter ARR1 EXP1 function Array Return an array with ARR1's elements that meet the EXP1 condition 0.5.1
Array.findMin ARR1 function Number array index of A1's minimal element 0.5.0
Array.findMax ARR1 function Number array index of A1's maximal element 0.5.0
Array.first ARR1 function Entity Return the first element of A1 0.5.2
Array.getAt ARR1 NUM1 function Entity get N1-th element from A1 array without removing it 0.5.1
Array.getAt! ARR1 NUM1 function Entity get N1-th element from A1 array and pop it from the array 0.5.1
Array.getHead ARR1 function Entity get the first element from A1 array without removing it 0.5.1
Array.getHead! ARR1 function Entity get the first element from A1 array and pop it from the array 0.5.1
Array.getTail ARR1 function Entity get the last element from A1 array without removing it 0.5.1
Array.getTail! ARR1 function Entity get the last element from A1 array and pop it from the array 0.5.1
Array.isEmpty ARR1 function Boolean Determine whether A1 is an empty array or not 0.5.2
Array.join ARR1 ARR2 function Array Join two arrays 0.5.1
Array.last ARR1 function Entity Return the last element of A1 0.5.2
Array.left ARR1 NUM1 function Array Build an array of the first N1 elements 0.5.1
Array.length ARR1 function Number Returns a length of A1 array 0.4.3
Array.map ARR1 FUN1 function Array Map A1 by applying an unary function F1 on each array's element 0.5.1
Array.pad ARR1 NUM1 function Array Fill an A1 array with nulls to reach the length of N1, and its old content is centered 0.5.2
Array.padLeft ARR1 NUM1 function Array Fill an A1 array with nulls to reach the length of N1, and its old content is right-justified 0.5.2
Array.padRight ARR1 NUM1 function Array Fill an A1 array with nulls to reach the length of N1, and its old content is left-justified 0.5.2
Array.padEntities ARR1 NUM1 ENT1 function Array Fill an A1 array with E1 to reach the length of N1, and its old content is centered 0.5.2
Array.padEntitiesLeft ARR1 NUM1 ENT1 function Array Fill an A1 array with E1 to reach the length of N1, and its old content is right-justified 0.5.2
Array.padEntitiesRight ARR1 NUM1 ENT1 function Array Fill an A1 array with E1 to reach the length of N1, and its old content is left-justified 0.5.2
Array.padSpaces ARR1 NUM1 function Array Fill an A1 array with space chars to reach the length of N1, and its old content is centered 0.5.2
Array.padSpacesLeft ARR1 NUM1 function Array Fill an A1 array with space chars to reach the length of N1, and its old content is right-justified 0.5.2
Array.padSpacesRight ARR1 NUM1 function Array Fill an A1 array with space chars to reach the length of N1, and its old content is left-justified 0.5.2
Array.padNulls ARR1 NUM1 function Array Fill an A1 array with nulls to reach the length of N1, and its old content is centered 0.5.2
Array.padNullsLeft ARR1 NUM1 function Array Fill an A1 array with nulls to reach the length of N1, and its old content is right-justified 0.5.2
Array.padNullsRight ARR1 NUM1 function Array Fill an A1 array with nulls to reach the length of N1, and its old content is left-justified 0.5.2
Array.padZeros ARR1 NUM1 function Array Fill an A1 array with zeros to reach the length of N1, and its old content is centered 0.5.2
Array.padZerosLeft ARR1 NUM1 function Array Fill an A1 array with zeros to reach the length of N1, and its old content is right-justified 0.5.2
Array.padZerosRight ARR1 NUM1 function Array Fill an A1 array with zeros to reach the length of N1, and its old content is left-justified 0.5.2
Array.padEmptyStrings ARR1 NUM1 function Array Fill an A1 array with empty strings to reach the length of N1, and its old content is centered 0.5.2
Array.padEmptyStringsLeft ARR1 NUM1 function Array Fill an A1 array with empty strings to reach the length of N1, and its old content is right-justified 0.5.2
Array.padEmptyStringsRight ARR1 NUM1 function Array Fill an A1 array with empty strings to reach the length of N1, and its old content is left-justified 0.5.2
Array.pop ARR1 function Array remove the last element of A1 array and return the new array (preserving the previous state) 0.5.1
Array.pop! ARR1 function Array remove the last element of A1 array and return the new array (overwriting the previous state) 0.5.1
Array.pop!! ARR1 function none remove the last element of A1 array (overwriting the previous state) 0.5.1
Array.popAt ARR1 NUM1 function Array remove the N1-th element of A1 array and return the new array (preserving the previous state) 0.5.1
Array.popAt! ARR1 NUM1 function Array remove the N1-th element of A1 array and return the new array (overwriting the previous state) 0.5.1
Array.popAt!! ARR1 NUM1 function none remove the N1-th element of A1 array (overwriting the previous state) 0.5.1
Array.push ARR1 ENT1 function Array add E1 to A1 array as the last element and return the new array (preserving the previous state) 0.5.1
Array.push! ARR1 ENT1 function Array add E1 to A1 array as the last element and return the new array (overwriting the previous state) 0.5.1
Array.push!! ARR1 ENT1 function none add E1 to A1 array as the last element (overwriting the previous state) 0.5.1
Array.pushAt ARR1 NUM1 ENT1 function Array add E1 to A1 array as the N1-th element and return the new array (preserving the previous state) 0.5.1
Array.pushAt! ARR1 NUM1 ENT1 function Array add E1 to A1 array as the N1-th element and return the new array (overwriting the previous state) 0.5.1
Array.pushAt!! ARR1 NUM1 ENT1 function none add E1 to A1 array as the N1-th element (overwriting the previous state) 0.5.1
Array.randomFrom ARR1 function Entity Get a random element from A1 0.5.2
Array.reduce ARR1 FUN1 ENT1 function Entity Reduce A1 left-to-right to single value using a binary function F1, starting with an entity E1 as initial value of an accumulator 0.5.1
Array.reduceFromFirst ARR1 FUN1 function Entity Reduce A1 left-to-right to single value using a binary function F1, starting with A1's first element as an initial value of an accumulator 0.5.1
Array.reduceLeft ARR1 FUN1 ENT1 function Entity Reduce A1 left-to-right to single value using a binary function F1, starting with an entity E1 as initial value of an accumulator 0.5.1.2
Array.reduceLeftFromFirst ARR1 FUN1 function Entity Reduce A1 left-to-right to single value using a binary function F1, starting with A1's first element as an initial value of an accumulator 0.5.1.2
Array.reduceRight ARR1 FUN1 ENT1 function Entity Reduce A1 right-to-left to a single value using a binary function F1, starting with an entity E1 as initial value of an accumulator 0.5.1
Array.reduceRightFromLast ARR1 FUN1 function Entity Reduce A1 right-to-left to a single value using a binary function F1, starting with A1's last element as an initial value of an accumulator 0.5.1
Array.reduceSum ARR1 function Number sum of the elements of A1 0.5.0
Array.reduceProduct ARR1 function Number product of the elements of A1 0.5.0
Array.reduceAvg ARR1 function Number arithmetic mean of the elements of A1 0.5.0
Array.reduceMean ARR1 function Number arithmetic mean of the elements of A1 0.5.0
Array.reduceMeanGeom ARR1 function Number geometric mean of the elements of A1 0.5.0
Array.reduceMeanHarmonic ARR1 function Number harmonic mean of the elements of A1 0.5.0
Array.reduceMeanSq ARR1 function Number square mean of the elements of A1 0.5.0
Array.reducePowerMean ARR1 NUM1 function Number N1-th power mean of the elements of A1 0.5.0
Array.reduceMedian ARR1 function Number median of the elements of A1 0.5.0
Array.reduceVariance ARR1 function Number variance of the elements of A1 0.5.0
Array.reduceStddev ARR1 function Number standard deviation of the elements of A1 0.5.0
Array.reduceStdDev ARR1 function Number alias for Array.reduceStddev 0.5.2
Array.reduceMin ARR1 function Number minimal value of the elements of A1 0.5.0
Array.reduceMax ARR1 function Number maximal value of the elements of A1 0.5.0
Array.reduceGCD ARR1 function Number Greatest common divisor (GCD) of the elements of A1 0.5.2
Array.reduceLCM ARR1 function Number Least common multiple (LCM) of the elements of A1 0.5.2
Array.right ARR1 NUM1 function Array Build an array of the last N1 elements 0.5.1
Array.setAt ARR1 NUM1 ENT1 function Array set E1 as N1-th element of A1 array and return the new array (preserving the previous state) 0.5.1
Array.setAt! ARR1 NUM1 ENT1 function Array set E1 as N1-th element of A1 array and return the new array (overwriting the previous state) 0.5.1
Array.setAt!! ARR1 NUM1 ENT1 function none set E1 as N1-th element of A1 array (overwriting the previous state) 0.5.1
Array.shift ARR1 function Array remove the first element of A1 array and return the new array (preserving the previous state) 0.5.1
Array.shift! ARR1 function Array remove the first element of A1 array and return the new array (overwriting the previous state) 0.5.1
Array.shift!! ARR1 function none remove the first element of A1 array (overwriting the previous state) 0.5.1
Array.sort ARR1 function Array Sort an array. If the first element of A1 is a string, then sort entities by their strings. Otherwise sort by numerical values. 0.5.2
Array.sortNumbers ARR1 function Array sort array by the numerical values 0.5.0
Array.sortStrings ARR1 function Array sort array by the string values alphabetically 0.5.0
Array.split ARR1 NUM1 function set(2) of Array Split an array to two separate arrays, where N1-th element becomes the first element of the latter array 0.5.1
Array.splitByExpression ARR1 EXP1 function set(2) of Array Split an array to two separate arrays, where the LHS array has values that pass the EXP1 logical expression and the RHS value has values that don't 0.5.1
Array.subarray ARR1 NUM1 NUM2 function Array Return a array that has N2 of A1's values, starting from N1 index 0.5.1
Array.toJSString ARR1 function String Returns an array string in a JS style (note: it works for other types too) 0.5.0
Array.trim ARR1 function Array Eliminate nulls on the both left and right sides of A1 0.5.2
Array.trimLeft ARR1 function Array Eliminate nulls on the left side of A1 0.5.2
Array.trimRight ARR1 function Array Eliminate nulls on the right side of A1 0.5.2
Array.trimNulls ARR1 function Array Eliminate nulls on the both left and right sides of A1 0.5.2
Array.trimNullsLeft ARR1 function Array Eliminate nulls on the left side of A1 0.5.2
Array.trimNullsRight ARR1 function Array Eliminate nulls on the right side of A1 0.5.2
Array.trimEntities ARR1 ENT1 function Array Eliminate E1s on the both left and right sides of A1 0.5.2
Array.trimEntitiesLeft ARR1 ENT1 function Array Eliminate E1s on the left side of A1 0.5.2
Array.trimEntitiesRight ARR1 ENT1 function Array Eliminate E1s on the right side of A1 0.5.2
Array.unweave ARR1 function set(2) of Array Split an array, where LHS array has odd indexes' values and RHS array has even ones 0.5.1
Array.weave ARR1 ARR2 function Array Join two arrays, where odd indexes have A1's values and even indexes have A2's values. In case when both arrays have different lengths, then the remaining values of the larger array are appended to the result array's tail 0.5.1

Obsolete functions

So far the only obsolete function are insertAt and reduceMoment, that were officially included in Leviathan for 2 days (namely 11/2/2020–11/4/2020 and 11/24/2021–11/26/2021 respectively). The following functions still exist, but their purpose changed slightly.

Package Function Syntax Output type Purpose Since Last version supported
Array.getAt ARR1 NUM1 function Entity get N1-th element from A1 array 0.4.3 0.5.0
Array.setAt ARR1 NUM1 ENT1 function Array set E1 as N1-th element of A1 array and return the new array (overwriting the previous state) 0.4.3 0.5.0
Array.push ARR1 ENT1 function Array add E1 to A1 array as the last element 0.4.3 0.5.0
Array.pop ARR1 function Entity remove and return the last element of A1 array 0.4.3 0.5.0
Array.pushAt ARR1 NUM1 ENT1 function Array add E1 to A1 array as the N1-th element 0.4.3 0.5.0
Array.popAt ARR1 NUM1 function Entity remove and return the N1-th element of A1 array 0.4.3 0.5.0
Array.shift ARR1 function Entity remove and return the first element of A1 array 0.4.3 0.5.0

Examples

  • [ 1 1 10 seq ] fun{ + } 0 Array.reduce returns 55 (as it is sum of numbers from 1 to 10)
  • [ 1 1 10 seq ] fun{ * } 1 Array.reduce returns 3628800 (as it is a product of numbers from 1 to 10, i.e. factorial of 10)
  • [ 1 1 10 seq ] fun{ + } Array.reduceFromFirst returns 55 (as it is sum of numbers from 1 to 10)
  • [ 1 1 10 seq ] Array.reduceSum also returns 55
  • [ 1 1 10 seq ] Array.reduceProduct also returns 3628800
  • [ 1 1 10 seq ] function { 2 ^ } Array.map returns [ 1 4 9 16 25 36 49 64 81 100 ], that is the array of items squared
  • [ 1 1 10 seq ] fun{ >x if ( [ 3 4 5 6 ] $x Array.belongs ) TRUE else FALSE } Array.map returns [ FALSE FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE ], that is an array where TRUE means that the value belongs to a set and FALSE means the opposite
  • [ 1 1 10 seq ] ( >x [ 3 1 6 seq ] $x Array.belongs ) Array.filter returns [ 3 4 5 6 ], that is all elements of [1..10] that belong to a set of [3..6]
  • [ 1 2 3 10 ] [ 5 6 7 ] Array.join returns [ 1 2 3 10 5 6 7 ]
  • [ 1 2 3 10 5 6 7 ] 4 Array.split returns [ 1 2 3 10 ] and [ 5 6 7 ]
  • [ -2 -1 0 1 2 ] ( 0 >= ) Array.filter returns [ 0 1 2 ]
  • [ -2 -1 0 1 2 ] ( 0 >= ) Array.splitByExpression returns [ 0 1 2 ] and [ -2 -1 ]
  • [ 1 1 11 seq ] Array.unweave returns [ 1 3 5 7 9 11 ] and [ 2 4 6 8 10 ]
  • [ 1 1 10 seq ] [ 10 1 1 seq ] Array.weave returns [ 1 10 2 9 3 8 4 7 5 6 6 5 7 4 8 3 9 2 10 1 ]
  • [ 1 1 10 seq ] 3 Array.left returns [ 1 2 3 ]
  • [ 1 1 10 seq ] 4 Array.right returns [ 7 8 9 10 ]
  • [ 1 1 10 seq ] 3 4 Array.subarray returns [ 4 5 6 7 ]
  • [ 1 1 10 seq ] 3 Array.crushBy returns [ 1 2 3 ] [ 4 5 6 ] [ 7 8 9 ] [ 10 ]