Creates a list of given start, end, value, and step parameters.
list(3); // 0, 1, 2, 3list(0, 3); // 0, 1, 2, 3list(0, 3, "y"); // y, y, y, ylist(0, 3, () => "y"); // y, y, y, ylist(0, 3, (i) => i); // 0, 1, 2, 3list(0, 3, (i) => `y${i}`); // y0, y1, y2, y3list(0, 3, obj); // obj, obj, obj, objlist(0, 6, (i) => i, 2); // 0, 2, 4, 6
npx atmx add helper list
Copy and paste the following method into @/utils/helpers/undefined.ts:
@/utils/helpers/undefined.ts
import { range } from "@/helpers/range.ts"; /*** Creates a list of given start, end, value, and step parameters.** @example* list(3) // 0, 1, 2, 3* list(0, 3) // 0, 1, 2, 3* list(0, 3, 'y') // y, y, y, y* list(0, 3, () => 'y') // y, y, y, y* list(0, 3, i => i) // 0, 1, 2, 3* list(0, 3, i => `y${i}`) // y0, y1, y2, y3* list(0, 3, obj) // obj, obj, obj, obj* list(0, 6, i => i, 2) // 0, 2, 4, 6*/export function list<T = number>(startOrLength: number,end?: number,valueOrMapper?: T | ((i: number) => T),step?: number,): T[] {return Array.from(range(startOrLength, end, valueOrMapper, step));}