Files
2022-09-07 21:10:26 +08:00

25 lines
512 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export class Counter {
private _min: number;
private _max: number;
private _last: number;
constructor(min: number = 1, max: number = Number.MAX_SAFE_INTEGER) {
this._min = min;
this._max = max;
this._last = max;
}
/** 复位从新从0开始计数 */
reset() {
this._last = this._max;
}
getNext() {
return this._last >= this._max ? (this._last = this._min) : ++this._last;
}
getlast() {
return this._last;
}
}