Skip to content

A library for array manipulation in JavaScript. This library is designed to make working with arrays a breeze, offering a set of easy-to-use functions

License

Notifications You must be signed in to change notification settings

Jeppe006/ArrayJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArrayJS

A library for array manipulation in JavaScript. This library is designed to make working with arrays a breeze, offering a set of easy-to-use functions

Installation
In an HTML document you get a script tag and link it to the library and it will automatically work for other of your scripts.

<script src="your/path/to/Array.js"></script>

Usage

MultiArray

const multiArray = new ArrayJS.MultiArray(3,3,0);
// Creates an new dimensional array that is 3x3 and sets the empty items as 0
// [0,0,0]
// [0,0,0]
// [0,0,0]

multiArray.Add(0,0,1); // adds 1 on row 0 & column 0
multiArray.Add(1,1,2); // adds 2 on row 1 & column 1
multiArray.Add(2,2,3); // adds 3 on row 2 & column 2

// To remove from the use Remove(Row, Column) function, it will set it as the default value
// To get the array itself use multiArray.array
console.log(multiArray.array);
Output: [1,0,0]
        [0,2,0]
        [0,0,3]


Compare

const array1 = [1,2,3,4];
const array2 = [1,2,3,4];
// Compares two arrays and if the arrays are equally long with the same items it will return true.
if(ArrayJS.Compare(array1,array2)){
  console.log("Passed!");
}
Output: Passed!


Shuffle

const array = [1,2,3,4];

console.log(ArrayJS.Shuffle(array)); // Randomizes the array.
Output: [3,2,4,1]


Swap

const array = [1,2,3,4];

console.log(ArrayJS.Swap(array,0,3)); // Swaps index of two items in an array.
Output: [4,2,3,1]


GenerateArray

// Generates an array as of which the items count from 1 to the respective length of the array.
console.log(ArrayJS.GenerateArray(5));
Output: [1,2,3,4,5]


DeepSearch

const array = [1,[ 2,3, ["secret", 4] ],5 ]

console.log(ArrayJS.DeepSearch(array,"secret"));
// Searches both the array and any nested arrays.
// If it finds nothing it will return undefined.
Output: {0: "secret", length: 1}


Equalize

const array = [1,2,2,3];
console.log(ArrayJS.Equalize(array));
// Counts all of the interger items to an minimum number.
// If not possible it will return null.
Output: 1


Split

const array = [1,2,3,4,5,6];
console.log(ArrayJS.Split(array,2)); 
// Splits the array in n interger amount of chunks.
Output: [ [1,2,3], [4,5,6] ]


FindRepeat

const array = [1,2,3,3];
console.log(ArrayJS.FindRepeat(array)); 
// Finds the first repeating item in the array and returns their index.
Output: 2


Max

const array = [1,2,3,4,5];
console.log(ArrayJS.Max(array,3)); 
// Sets an max cap on the array anything above the max cap will be set to the max value.
Output: [1,2,3,3,3]


Min

const array = [1,2,3,4,5];
console.log(ArrayJS.Min(array,3)); 
// Sets an minimum cap on the array anything below the minimum cap will be set to the minimum value.
Output: [3,3,3,4,5]


Clamp

const array = [1,2,3,4,5,6,7,8,9,10];
console.log(ArrayJS.Clamp(array,3,7)); 
// Clamp is both Max & Min together.
Output: [3,3,3,4,5,6,7,7,7,7]


Unique

const array = [1,1,2,2,3,3];
console.log(ArrayJS.Unique(array)); 
// Removes any repeating items.
Output: [1,2,3]


Last

const array = [1,2,3,4];
console.log(ArrayJS.Last(array,2)); 
// Gets the last part of the array respective of the amount.
Output: [3,4]

Sorting Algorithms

They all achieve they same thing of sorting the array but they are using different techniques
More info: https://en.wikipedia.org/wiki/Sorting_algorithm