/**
 * @param {Array} arr An array to process.
 */ "use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get arrayAvg () {
        return arrayAvg;
    },
    get arrayEach () {
        return arrayEach;
    },
    get arrayFilter () {
        return arrayFilter;
    },
    get arrayFlatten () {
        return arrayFlatten;
    },
    get arrayMap () {
        return arrayMap;
    },
    get arrayMax () {
        return arrayMax;
    },
    get arrayMin () {
        return arrayMin;
    },
    get arrayReduce () {
        return arrayReduce;
    },
    get arraySum () {
        return arraySum;
    },
    get arrayToString () {
        return arrayToString;
    },
    get arrayUnique () {
        return arrayUnique;
    },
    get extendArray () {
        return extendArray;
    },
    get getDifferenceOfArrays () {
        return getDifferenceOfArrays;
    },
    get getIntersectionOfArrays () {
        return getIntersectionOfArrays;
    },
    get getUnionOfArrays () {
        return getUnionOfArrays;
    },
    get pivot () {
        return pivot;
    },
    get stringToArray () {
        return stringToArray;
    },
    get to2dArray () {
        return to2dArray;
    }
});
function to2dArray(arr) {
    const ilen = arr.length;
    let i = 0;
    while(i < ilen){
        arr[i] = [
            arr[i]
        ];
        i += 1;
    }
}
function extendArray(arr, extension) {
    const ilen = extension.length;
    let i = 0;
    while(i < ilen){
        arr.push(extension[i]);
        i += 1;
    }
}
function pivot(arr) {
    const pivotedArr = [];
    if (!arr || arr.length === 0 || !arr[0] || arr[0].length === 0) {
        return pivotedArr;
    }
    const rowCount = arr.length;
    const colCount = arr[0].length;
    for(let i = 0; i < rowCount; i++){
        for(let j = 0; j < colCount; j++){
            if (!pivotedArr[j]) {
                pivotedArr[j] = [];
            }
            pivotedArr[j][i] = arr[i][j];
        }
    }
    return pivotedArr;
}
function arrayReduce(array, iteratee, accumulator, initFromArray) {
    let index = -1;
    let iterable = array;
    let result = accumulator;
    if (!Array.isArray(array)) {
        iterable = Array.from(array);
    }
    const length = iterable.length;
    if (initFromArray && length) {
        index += 1;
        result = iterable[index];
    }
    index += 1;
    while(index < length){
        result = iteratee(result, iterable[index], index, iterable);
        index += 1;
    }
    return result;
}
function arrayFilter(array, predicate) {
    let index = 0;
    let iterable = array;
    if (!Array.isArray(array)) {
        iterable = Array.from(array);
    }
    const length = iterable.length;
    const result = [];
    let resIndex = -1;
    while(index < length){
        const value = iterable[index];
        if (predicate(value, index, iterable)) {
            resIndex += 1;
            result[resIndex] = value;
        }
        index += 1;
    }
    return result;
}
function arrayMap(array, iteratee) {
    let index = 0;
    let iterable = array;
    if (!Array.isArray(array)) {
        iterable = Array.from(array);
    }
    const length = iterable.length;
    const result = [];
    let resIndex = -1;
    while(index < length){
        const value = iterable[index];
        resIndex += 1;
        result[resIndex] = iteratee(value, index, iterable);
        index += 1;
    }
    return result;
}
function arrayEach(array, iteratee) {
    let index = 0;
    let iterable = array;
    if (!Array.isArray(array)) {
        iterable = Array.from(array);
    }
    const length = iterable.length;
    while(index < length){
        if (iteratee(iterable[index], index, iterable) === false) {
            break;
        }
        index += 1;
    }
    return array;
}
function arraySum(array) {
    return arrayReduce(array, (a, b)=>a + b, 0);
}
function arrayMax(array) {
    return arrayReduce(array, (a, b)=>a > b ? a : b, Array.isArray(array) ? array[0] : undefined);
}
function arrayMin(array) {
    return arrayReduce(array, (a, b)=>a < b ? a : b, Array.isArray(array) ? array[0] : undefined);
}
function arrayAvg(array) {
    if (!array.length) {
        return 0;
    }
    return arraySum(array) / array.length;
}
function arrayFlatten(array) {
    return arrayReduce(array, (initial, value)=>initial.concat(Array.isArray(value) ? arrayFlatten(value) : value), []);
}
function arrayUnique(array) {
    const unique = [];
    arrayEach(array, (value)=>{
        if (unique.indexOf(value) === -1) {
            unique.push(value);
        }
    });
    return unique;
}
function getDifferenceOfArrays(...arrays) {
    const [first, ...rest] = [
        ...arrays
    ];
    let filteredFirstArray = first;
    arrayEach(rest, (array)=>{
        filteredFirstArray = filteredFirstArray.filter((value)=>!array.includes(value));
    });
    return filteredFirstArray;
}
function getIntersectionOfArrays(...args) {
    const lastArgument = args[args.length - 1];
    let comparator;
    let arrays = args;
    if (typeof lastArgument === 'function') {
        comparator = lastArgument;
        arrays = arrays.slice(0, -1);
    }
    const isMatch = comparator ? (value, array)=>array.some((item)=>comparator(value, item)) : (value, array)=>array.includes(value);
    const [first, ...rest] = arrays;
    let filteredFirstArray = first;
    arrayEach(rest, (array)=>{
        filteredFirstArray = filteredFirstArray.filter((value)=>isMatch(value, array));
    });
    return filteredFirstArray;
}
function getUnionOfArrays(...arrays) {
    const [first, ...rest] = [
        ...arrays
    ];
    const set = new Set(first);
    arrayEach(rest, (array)=>{
        arrayEach(array, (value)=>{
            if (!set.has(value)) {
                set.add(value);
            }
        });
    });
    return Array.from(set);
}
function stringToArray(value, delimiter = ' ') {
    return value.split(delimiter);
}
function arrayToString(array, separator = ' ') {
    return array.join(separator);
}
