* Creates an array of a specified length and populates it with the results of calling a provided function on every index in the array.
* @template T - The type of elements in the resulting array.
* @param length - The length of the array to create.
* @param [transform=(_, index) => index] - The function to call on every index in the array. By default, it returns the index itself.
* @returns An array of length `length` with its elements being the result of the `transform` function.
* // Create an array of numbers
* const numbers = createArray(5, (_, index) => index * 2);
* console.log(numbers); // [0, 2, 4, 6, 8]
* // Create an array of strings
* const strings = createArray(5, (_, index) => `Item ${index}`);
* console.log(strings); // ['Item 0', 'Item 1', 'Item 2', 'Item 3', 'Item 4']
* // Create an array of numbers using the default transform function
* const defaultNumbers = createArray(5);
* console.log(defaultNumbers); // [0, 1, 2, 3, 4]
export const createArray = <T = number>(
transform: Parameters<typeof Array.from<T, U>>[1] = (_, index) => index,
): T[] => Array.from({ length }, transform)
* Creates an array of numbers (positive and/or negative) progressing from
* `start` up to `end` (included).
* @param start - The start of the range.
* @param [end] - The end of the range.
* @param [step=1] - The value to increment or decrement by.
* @returns Returns the range of numbers.
* // => [0, -1, -2, -3, -4]
* // => [0, 5, 10, 15, 20]
export const range = (start: number, end?: number, step = 1): number[] => {
const adjustedStart = end === undefined ? 0 : start
const adjustedEnd = end === undefined ? start : end
const length = Math.ceil((adjustedEnd - adjustedStart) / step) + 1
return Array.from({ length }, (_, i) => adjustedStart + i * step)