/**
 * @since Last modified: 2023-12-27 10:32:38
 * @function arrange
 * @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 arrangement.
 * @returns {string}  - Returns the new array after arrange.
 * @see {@link https://codepen.io/axui/pen/bGZNKve|demo @ codepen}
 * @example
 * ax.arrange({origin:[1,2,3],length:2});
 * <!--Return [[1,2],[1,3],[2,3]]-->
 * ax.arrange({origin:[1,2,3,4,5],length:2,start:2});
 * <!--Return [[3,4],[3,5],[4,5]]-->
 */
'use strict';
const arrange = ({ origin, length = 2, start = 0, splice = [], result = [] }) => {
    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 && arrange({ origin, length, start: i + 1, splice, result });
            break;
        }
        arrange({ origin, length: length - 1, start: i + 1, splice: [...splice, origin[i]], result });
    }
    return result || [];
};
export default arrange;
