Skip to content

Commit

Permalink
chore(disunite util function): 건물을 찾는 함수를 유틸 함수로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
hwinkr committed Dec 22, 2023
1 parent 61318b5 commit cea93ff
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/utils/map/get-building-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PKNU_BUILDINGS } from '@constants/pknu-map';
import { BuildingType } from '@type/map';

const getBuildingInfo = (
keyword: string,
): [BuildingType, number] | undefined => {
const splittedKeyword = keyword.split(' ').join('').toUpperCase();

for (const buildingType of Object.keys(PKNU_BUILDINGS)) {
const index = PKNU_BUILDINGS[
buildingType as BuildingType
].buildings.findIndex(
(PKNU_BUILDING) =>
PKNU_BUILDING.buildingName === splittedKeyword ||
PKNU_BUILDING.buildingNumber === splittedKeyword,
);
if (index !== -1) return [buildingType as BuildingType, index];
}

return;
};

export default getBuildingInfo;

0 comments on commit cea93ff

Please sign in to comment.