/**
 * @since Last modified: 2023-12-28 19:28:32
 * @function combineArr
 * @description Arrange and combine the items in the array completely.
 * @param {object} obj - Parameters.
 * @param {any[]} obj.origin - Origin array.
 * @param {number} [obj.length=2] - The length of each child array.
 * @param {number} [obj.start=0] - Index start of origin index.
 * @param {array} [obj.splice] - Temporarily save data.
 * @param {array} [obj.result] - Completed data combined.
 * @returns {string}  - Returns the new array after combination.
 * @see {@link https://codepen.io/axui/pen/bGZNKve|demo @ codepen}
 * @example
 * ax.combineArr({origin:[1,2,3],length:2});
 * <!--Return [[1,2],[1,3],[2,3]]-->
 * ax.combineArr({origin:[1,2,3,4,5],length:2,start:2});
 * <!--Return [[3,4],[3,5],[4,5]]-->
 */
'use strict';
const combineArr = ({ origin, length=2, start = 0, splice = [], result = [] }: { origin: any[], length: number, start?: number, splice?: any[], result?: any[] }) => {
    let arrayLen = origin.length
    if (start + length > arrayLen) {
        return [];
    }
    for (let i = start; i < arrayLen; i++) {
        if (length === 1) {
            result.push([...splice, origin[i]]);
            i + 1 < arrayLen && combineArr({ origin, length, start: i + 1, splice, result });
            break;
        }
        combineArr({ origin, length: length - 1, start: i + 1, splice: [...splice, origin[i]], result });
    }
    return result || [];
}
export default combineArr;
