From 959f0bf656b773621beb761f752dc66cf0a27e4f Mon Sep 17 00:00:00 2001 From: Florian Schmid Date: Fri, 21 Apr 2023 23:22:19 +0200 Subject: [PATCH] add nextround method + explicit types --- src/cpuRepository.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cpuRepository.ts b/src/cpuRepository.ts index 7ebecdf..471416d 100644 --- a/src/cpuRepository.ts +++ b/src/cpuRepository.ts @@ -21,14 +21,22 @@ export class CpuRepository { } getRandomCpu() { - let randomIndex = this.#getRandomInt(0, this.#cpuList.length); + let randomIndex: number; + do { + randomIndex = this.#getRandomInt(0, this.#cpuList.length); + } while (this.#cpuList[randomIndex]["value"] == null || this.#cpuList[randomIndex]["type"] == null) this.#cpuList[randomIndex]["name"] = this.#cpuList[randomIndex]["name"].split('@')[0]; return this.#cpuList[randomIndex]; } - #getRandomInt(min, max) { + #getRandomInt(min, max): number { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive } + + nextRound(): void { + this.#currentCPU = this.#nextCPU + this.#nextCPU = this.getRandomCpu(); + } } \ No newline at end of file