This package describes some of the array method
npm i jsarraymethods
const jsarraymethods=require('jsarraymethods');
Sorts the given array in ascending order.
let arr = [15, 25, 58, 7, 2, 63];
let result = jsarraymethods.sort(arr); //output should be [2, 7, 15, 25, 58, 63]
Reverse sorting gives the array sorted in descending order.
let arr = [15, 25, 58, 7, 2, 63];
let result = jsarraymethods.rev_sort(arr); //output should be [63, 58, 25, 15, 7, 2]
Finds the first element in the array.
let arr = [15, 25, 58, 7, 2, 63];
let result = jsarraymethods.first_element(arr); //output should be 15
Finds the last element in the array.
let arr = [15, 25, 58, 7, 2, 63];
let result = jsarraymethods.last_element(arr); //output should be 63
Finds the middle element in a array.
let arr = [15, 25, 58, 7, 2, 63];
let result = jsarraymethods.middle_element(arr); //output should be 58
Finds the length of the array.
let arr = [15, 25, 58, 7, 2, 63];
let result = jsarraymethods.len_array(arr); //output should be 6
Finds the element at a particular index.
let arr = [15, 25, 58, 7, 2, 63];
let result = jsarraymethods.len_array(arr, 2); //output should be 58
Joins two array and the resultant array would be sorted in ascending order.
let arr = [15, 25, 58, 7, 2, 63];
let arr1 = [84, 56, 42, 50, 35, 94];
let result = jsarraymethods.join_ascending(arr, arr1); //output will be [2, 7, 15, 25, 35, 42, 50, 56, 58, 63, 84, 94]
Joins two array and the resultant array would be sorted in descending order.
let arr = [15, 25, 58, 7, 2, 63];
let arr1 = [84, 56, 42, 50, 35, 94];
let result = jsarraymethods.join_ascending(arr, arr1); //output will be [94, 84, 63, 58, 56, 50, 42, 35, 25, 15, 7, 2]
Removes last element from the array and returns the new array.
let arr = [15, 25, 58, 7, 2, 63];
let result = jsarraymethods.del_last(arr); //output will be [15, 25, 58, 7, 2]
Removes the first element from the array and returns the new array
let arr = [15, 25, 58, 7, 2, 63];
let result = jsarraymethods.del_first(arr); //output will be [25, 58, 7, 2, 63]
let arr = [15, 25, 58, 7, 2, 63]
let result = jsarraymethods.del_index_element(arr, 2); //output will be [15, 25, 7, 2, 63]