/**
 * @since Last modified: 2024/03/04 21:18:28
 * @function increaseId
 * @description Get a new ID based on an existing array (could be array length value, or max value in array ids + 1).
 * @param {any[]} data  - Any one of the arrays.
 * @param {boolean} [hasId=true]  - Whether the array contains the "id" property.
 * @returns {number} - Return the new id.
 * @see {@link https://codepen.io/axui/pen/LYvVpQj|demo @ codepen}
 * @example
 * let x =['a','b','c'];
 * ax.increaseId(x,false);
 * <!--return 3-->
 */




'use strict';
const increaseId = (data: any[], hasId: boolean = true):number => {
    let ids: number[] = [],
        newId = 0;
    if (hasId) {
        
        data.forEach(i => {
            ids.push(~~i.id);
        });
        
        newId = Math.max(...ids) + 1;
    } else {
        
        newId = data.length;
    }
    return newId;
}
export default increaseId;
