export class ArrayUtils {
  static pick<T>(array: T[]): T {
    return array[Math.round(Math.random() * (array.length - 1))];
  }
  static pickMultiple<T>(array: T[], amount: number): T[] {
    return array.toSorted(() => 0.5 - Math.random()).slice(0, amount);
  }
}

export class NumberUtils {
  static clamp(number: number, min: number, max: number) {
    return Math.max(min, Math.min(number, max));
  }
  static isBetween(number: number, min: number, max: number) {
    return number >= min && number <= max;
  }
  static pickRandom(min: number, max: number) {
    return min + (Math.random() * (max - min));
  }
}

export class StringUtils {
  static truncate(string: string, length: number) {
    if (string.length <= length) {
      return string;
    } else {
      return string.slice(0, length - 3) + "...";
    }
  }
}

export class ObjectUtils {
  static isObject(object: any) {
    if (object == null) return false;
    return object.constructor === Object;
  }

  static isEmpty(object: any) {
    return Object.keys(object).length === 0;
  }

  static navigatePath(object: any, path: string) {
    return path.split(".").reduce((objnav: any, pathseg: string) => {
      return objnav[pathseg];
    }, object);
  }
}
