mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-09-26 07:48:12 +08:00
type range
This commit is contained in:
+23
-15
@@ -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(arr, start, step, count) {
|
||||
function _doFill(
|
||||
arr: Array<number>,
|
||||
start: number,
|
||||
step: number,
|
||||
count: number
|
||||
) {
|
||||
for (let idx = 0, val = start; idx < count; idx += 1, val += step) {
|
||||
arr[idx] = val;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'arr' implicitly has an 'any' type.
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||
export function rangeFill(arr, start = 0, step = 1) {
|
||||
export function rangeFill(
|
||||
arr: Array<number>,
|
||||
start = 0,
|
||||
step = 1
|
||||
): Array<number> {
|
||||
return _doFill(arr, start, step, arr.length);
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'start' implicitly has an 'any' type.
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||
export function range(start, stop, step) {
|
||||
export function range(
|
||||
start: number,
|
||||
stop?: number,
|
||||
step?: number
|
||||
): Array<number> {
|
||||
if (start === undefined) return [];
|
||||
if (stop === undefined) {
|
||||
stop = start;
|
||||
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);
|
||||
return _doFill(new Array(len), start, step, len);
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'start' implicitly has an 'any' type.
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
|
||||
export function linspace(start, stop, nsteps) {
|
||||
// @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
|
||||
const delta = (stop - start) / (nsteps - 1).toFixed();
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'i' implicitly has an 'any' type.
|
||||
export function linspace(
|
||||
start: number,
|
||||
stop: number,
|
||||
nsteps: number
|
||||
): Array<number> {
|
||||
const delta = (stop - start) / Number((nsteps - 1).toFixed());
|
||||
return range(0, nsteps, 1).map((i) => start + i * delta);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user