type range

This commit is contained in:
Seve Badajoz
2021-08-12 16:35:27 -07:00
parent bff996066d
commit a6afd4ef11
+23 -15
View File
@@ -22,38 +22,46 @@ rangeFill(array, start, step) -> array
*/ */
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'arr' implicitly has an 'any' type. function _doFill(
function _doFill(arr, start, step, count) { arr: Array<number>,
start: number,
step: number,
count: number
) {
for (let idx = 0, val = start; idx < count; idx += 1, val += step) { for (let idx = 0, val = start; idx < count; idx += 1, val += step) {
arr[idx] = val; arr[idx] = val;
} }
return arr; return arr;
} }
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'arr' implicitly has an 'any' type. export function rangeFill(
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS. arr: Array<number>,
export function rangeFill(arr, start = 0, step = 1) { start = 0,
step = 1
): Array<number> {
return _doFill(arr, start, step, arr.length); return _doFill(arr, start, step, arr.length);
} }
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'start' implicitly has an 'any' type. export function range(
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS. start: number,
export function range(start, stop, step) { stop?: number,
step?: number
): Array<number> {
if (start === undefined) return []; if (start === undefined) return [];
if (stop === undefined) { if (stop === undefined) {
stop = start; stop = start;
start = 0; start = 0;
} }
step = step || 1; // catch undefind and zero step = step || 1; // catch undefined and zero
const len = Math.max(Math.ceil((stop - start) / step), 0); const len = Math.max(Math.ceil((stop - start) / step), 0);
return _doFill(new Array(len), start, step, len); return _doFill(new Array(len), start, step, len);
} }
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'start' implicitly has an 'any' type. export function linspace(
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS. start: number,
export function linspace(start, stop, nsteps) { stop: number,
// @ts-expect-error ts-migrate(2363) FIXME: The right-hand side of an arithmetic operation mus... Remove this comment to see the full error message nsteps: number
const delta = (stop - start) / (nsteps - 1).toFixed(); ): Array<number> {
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'i' implicitly has an 'any' type. const delta = (stop - start) / Number((nsteps - 1).toFixed());
return range(0, nsteps, 1).map((i) => start + i * delta); return range(0, nsteps, 1).map((i) => start + i * delta);
} }