array-lib
A library for array functions in Array.prototype
Installation
npm install array-lib
Usage
const arrayLib = ;
clone
deep copy an array
let arr = 123;let clone_arr = arr;
print
arr;//=> [1,2,3]"hello";// =>hello123;//=>123a:12;//=>{a:12}
max
Retrun max value from array
arr;
maxIndex
Returns index of max value in array:
arr
remove
Removes element at the specified position
arr; arr//=> [2,3]
removeVal
Removes first or all values from array
let a = 1234455;let remove_all_elements = true;a; a;//=> [1,2,3,5,5];
count
Count how much times a element is in an array
let b = "a""b""b""c""b";console;//=> 3
replace
Replace elements in array
let c = 123334669;c; c;//=>[1,2,"d","d","d",4,6,6,9]
addUp
Add up all numbers in array
let d = 12345; d;//=> 15
matrix
Create a 2d array
let arr = Arrayarr;//=>//[ // [ 'fill', 'fill', 'fill' ],// [ 'fill', 'fill', 'fill' ]// ]
vector
Create an array
let arr = Array;arr;//=> ['fill', 'fill', 'fill','fill', 'fill', 'fill']
toArray
Create an array from a string
"hello ,world ,how ,are ,you";//=> //[ 'hello', 'world', 'how', 'are', 'you' ]
multiplyMatrices
let b = 1234b//=>[ [ 13, 18 ], [ 27, 40 ] ]
isMatrix
check if an array is a 2d matrix
let matrix = 012 345 678 ; matrix// => true
avrage
get Avrage from array
12345;//=> 3
pos
return first position of element in an array
12345;//=>3 12345;//=>false
getAllPos
Get all positions of element in array
let arr = 134487534;b;//=> [2,3,8]
shuffle
shuffle an array
123456789; //=> [ 7, 2, 9, 1, 6, 8, 3, 5, 4 ]
range
A function to create flexibly-numbered lists of integers
Array;//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]Array;//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]Array;//=> [0, 5, 10, 15, 20, 25]Array;//=> [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]Array;//=> []
without
Returns a copy of the array with all instances of the values removed.
let a = 1231231231123let b = a;b; //=>[ 3, 31, 31, 3 ]