import { isNaN } from '../utils/validate/number';

export function times(n: number, iteratee: (index: number) => any[]) {
  let index = -1;
  const result = Array(n);

  while (++index < n) {
    result[index] = iteratee(index);
  }

  return result;
}

export function getTrueValue(value: string | undefined): number | undefined {
  if (!value) {
    return;
  }

  while (isNaN(parseInt(value, 10))) {
    value = value.slice(1);
  }

  return parseInt(value, 10);
}

export function getMonthEndDay(year: number, month: number): number {
  return 32 - new Date(year, month - 1, 32).getDate();
}
