From fba60df9d1ef75e52e2b85340d7b9ee54763e6b5 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Fri, 29 Jul 2022 01:24:09 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20binarysearch=20=EC=83=81=ED=95=9C=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/ts/utilGame/formatConnectScore.ts | 4 +++- hwe/ts/utilGame/formatDefenceTrain.ts | 4 +++- hwe/ts/utilGame/formatDexLevel.ts | 3 ++- hwe/ts/utilGame/formatHonor.ts | 4 +++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/hwe/ts/utilGame/formatConnectScore.ts b/hwe/ts/utilGame/formatConnectScore.ts index 8b68ca13..6ba23ac7 100644 --- a/hwe/ts/utilGame/formatConnectScore.ts +++ b/hwe/ts/utilGame/formatConnectScore.ts @@ -1,4 +1,5 @@ import bs from 'binary-search'; +import { clamp } from 'lodash'; const connectMap: [number, string][] = [ [0, '안함'], @@ -18,5 +19,6 @@ export function formatConnectScore(connect: number) { if (idx >= 0) { return connectMap[idx][1] ?? '?'; } - return connectMap[-(idx + 1)][1] ?? '?'; + const uidx = clamp(-idx - 1, 0, connectMap.length - 1); + return connectMap[uidx][1] ?? '?'; } \ No newline at end of file diff --git a/hwe/ts/utilGame/formatDefenceTrain.ts b/hwe/ts/utilGame/formatDefenceTrain.ts index cdbafe67..56051149 100644 --- a/hwe/ts/utilGame/formatDefenceTrain.ts +++ b/hwe/ts/utilGame/formatDefenceTrain.ts @@ -1,4 +1,5 @@ import bs from 'binary-search'; +import { clamp } from 'lodash'; const defenceMap: [number,string][] = [ [0, "△"], @@ -13,5 +14,6 @@ export function formatDefenceTrain(defenceTrain: number): string { if(idx >= 0){ return defenceMap[idx][1]??'?'; } - return defenceMap[-(idx + 1)][1]??'?'; + const uidx = clamp(-idx - 1, 0, defenceMap.length - 1); + return defenceMap[uidx][1]??'?'; } \ No newline at end of file diff --git a/hwe/ts/utilGame/formatDexLevel.ts b/hwe/ts/utilGame/formatDexLevel.ts index 6a608044..3ea86033 100644 --- a/hwe/ts/utilGame/formatDexLevel.ts +++ b/hwe/ts/utilGame/formatDexLevel.ts @@ -1,4 +1,5 @@ import bs from 'binary-search'; +import { clamp } from 'lodash'; export const DexLevelMap: [number, string, string][] = [ [0, 'navy', 'F-'], @@ -38,7 +39,7 @@ export type DexInfo = { export function formatDexLevel(dex: number): DexInfo { const rawIdx = bs(DexLevelMap, dex, ([dexKey], needle) => dexKey - needle); - const level = rawIdx >= 0 ? rawIdx : -(rawIdx + 1); + const level = rawIdx >= 0 ? rawIdx : clamp(-(rawIdx + 1), 0, DexLevelMap.length - 1); const [, color, name] = DexLevelMap[level]; diff --git a/hwe/ts/utilGame/formatHonor.ts b/hwe/ts/utilGame/formatHonor.ts index 54215b12..4a121107 100644 --- a/hwe/ts/utilGame/formatHonor.ts +++ b/hwe/ts/utilGame/formatHonor.ts @@ -1,4 +1,5 @@ import bs from 'binary-search'; +import { clamp } from 'lodash'; const hornorMap: [number, string][] = [ [0, '전무'], @@ -22,5 +23,6 @@ export function formatHonor(experience: number): string { if (idx >= 0) { return hornorMap[idx][1] ?? '?'; } - return hornorMap[-(idx + 1)][1] ?? '?'; + const uidx = clamp(-idx - 1, 0, hornorMap.length - 1); + return hornorMap[uidx][1] ?? '?'; } \ No newline at end of file