export default class ArrayUtil {
    static mergeStringArrays(array1, array2) {
        return ArrayUtil.removeDuplicates([...array1, ...array2]);
    }
    static isStringArrayEqual(array1, array2) {
        return ArrayUtil.isEqual(array1, array2);
    }
    static removeDuplicates(array) {
        return array.filter((value, index, self) => {
            return self.indexOf(value) === index;
        });
    }
    static shuffle(array) {
        const shuffledArray = [...array];
        for (let i = shuffledArray.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            if (!shuffledArray[i]) {
                continue;
            }
            if (!shuffledArray[j]) {
                continue;
            }
            [shuffledArray[i], shuffledArray[j]] = [
                shuffledArray[j],
                shuffledArray[i],
            ];
        }
        return shuffledArray;
    }
    static removeDuplicatesFromObjectIDArray(array) {
        const distinctIds = [];
        for (const objectId of array) {
            if (distinctIds.filter((item) => {
                return item.toString() === objectId.toString();
            }).length > 0) {
                continue;
            }
            distinctIds.push(objectId);
        }
        return distinctIds;
    }
    static isEqual(a, b) {
        // Check if the arrays have the same length
        if (a.length !== b.length) {
            return false;
        }
        // Sort both arrays by their JSON representation
        const sortedArr1 = JSON.stringify([...a].sort());
        const sortedArr2 = JSON.stringify([...b].sort());
        // Compare the sorted arrays
        return sortedArr1 === sortedArr2;
    }
    static sortByFieldName(fieldName) {
        return (a, b) => {
            if (a[fieldName] < b[fieldName]) {
                return -1;
            }
            if (a[fieldName] > b[fieldName]) {
                return 1;
            }
            return 0;
        };
    }
    static selectItemByRandom(array) {
        return array[Math.floor(Math.random() * array.length)];
    }
    static distinctByFieldName(array, fieldName) {
        // Get the distinct values by field name of the array
        const distinctValues = array
            .map((item) => {
            return item[fieldName];
        })
            .filter((value, index, self) => {
            return self.indexOf(value) === index;
        });
        // Create a new array with the distinct values
        const distinctArray = [];
        for (const value of distinctValues) {
            const item = array.find((item) => {
                return item[fieldName] === value;
            });
            distinctArray.push(item);
        }
        return distinctArray;
    }
}
//# sourceMappingURL=Array.js.map