fix: binarysearch 상한 에러
This commit is contained in:
@@ -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] ?? '?';
|
||||
}
|
||||
@@ -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]??'?';
|
||||
}
|
||||
@@ -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];
|
||||
|
||||
|
||||
@@ -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] ?? '?';
|
||||
}
|
||||
Reference in New Issue
Block a user