스트링 디코드 문제에서 망하고, 43분 후 복수에 성공한 이야기 (feat. 중첩 괄호도 처리함)

## 🔧 배경 얼마 전 기술 면접을 보다가 `decodeString` 문제를 받았습니다. 알고리즘 공부는 주로 BFS, DFS 쪽만 하던 터라, 문자열 파싱 문제에서 완전히 발목 잡혔습니다. 거기다 라이브 코딩. 제한 시간 30분. 당연히… 못 풀었죠. 멘탈까지 디코딩당한 날이었습니다. --- ## 🔥 복수의 시작 면접이 끝난 뒤에도 이 문제는 계속 머릿속을 맴돌았습니다. “내가 이걸 못 풀었다고? 진짜?” 그 순간부터 **마음속의 디버거**가 켜졌고, 라이브 코딩에서 시도했던 방식에서 출발해 다시 파기 시작했습니다. 스택도 쓰지 않았습니다. 재귀도 쓰지 않았습니다. 그냥 제 방식대로, 끈질기게 문자열을 조작하면서 풀었습니다. **걸린 시간: 추가 43분.** --- ## 🧠 접근 방식 요약 - `[`와 `]`를 찾는다. 가장 안쪽 괄호부터 시작. - 그 안의 문자열을 꺼내고, 반복 횟수를 계산한다. - 원래 문자열 배열을 `splice`로 조작해서 새로운 문자열을 삽입한다. - 그리고… **처음부터 다시 돌린다.** - 이걸 괄호가 다 없어질 때까지 반복한다. 사실상 **재귀를 흉내 내는 루프 기반 수동 파서**입니다. --- ## ✅ 최종 코드 (with 주석) ```javascript /** * @param {string} s * @return {string} */ var decodeString = function(s) { const strArr = s.split(''); let startIndex = -1; let endIndex = -1; for(let i = 0; i = 0 && endIndex >= 0 && endIndex > startIndex){ const addedStr = strArr.slice(startIndex + 1, endIndex).join(''); ...

react-native hook dependency setting (feat.RN-0.76)


react 리렌더링에 큰 영향을 미치는 hook dependency. 예전에는 lint 로 hook dependency 체크해주는 설정이 잘 안되어 힘들었던 기억이 나서 정리해보고자 새로운 리엑트 네이티브 프로젝트를 생성했다.
React re-rendering is significantly affected by hook dependencies. In the past, it was challenging for me to configure linting to check hook dependencies, so I created a new React Native project to document settings for managing them.

그런데 아무런 설정 없이도 hook dependency check 가 자동으로 잘 된다...?
To my surprise, the hook dependency check works automatically, even without any additional setup.


.eslintrc.js 파일을 살펴보니 (예전에는 자동으로 생성이 안되었던 것 같은데)
After reviewing the .eslintrc.js file (which didn’t seem to auto-generate in previous versions), I found this configuration:
```
module.exports = {
  root: true,
  extends: '@react-native',
};

```

하여 node_modules/@react-native 를 살펴보니

eslint-config/index.js 에 아래와 같은 설정을 발견

I explored node_modules/@react-native and found the following settings in eslint-config/index.js:
```
plugins: [
    'eslint-comments',
    'react',
    'react-hooks',
    'react-native',
    '@react-native',
    'jest',
  ],
```

시험삼아 `react-hooks` 를 삭제해보니 dependency check 가 작동하지 않는다.
When I removed react-hooks as a test, the dependency check stopped working.

굿.
Good.

# 추가
 expo를 사용하면서 네이티브 모듈을 사용하려고 create-expo-app --template bare-minimum을 하니 위에 적어놓았던 기본설정이 하나도 안붙어있었다...

1. typescript 세팅
2. eslint

yarn eslint --init 후

eslint.config.mjs에서

```
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReact from "eslint-plugin-react";
import reactHooks from "eslint-plugin-react-hooks";


/** @type {import('eslint').Linter.Config[]} */
export default [
  {files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"]},
  {languageOptions: { globals: globals.browser }},
  pluginJs.configs.recommended,
  ...tseslint.configs.recommended,
  pluginReact.configs.flat.recommended,
  {
    plugins: {
      "react-hooks":reactHooks,
    },
  rules:{"react-hooks/exhaustive-deps":"error"}
  }
];

```

웹스톰에서 에러가 발생하지 않아 살펴보니 최신 버전이 아니어서 eslint 9 버전의 eslint.config.mjs 를 인식하지 못했던 것.

vscode 에서는 잘 작동함

Comments

Popular posts from this blog

Operating System Concepts 9th

스티키 헤더 여러개 만들기 (Multiple sticky header)

Operating System Concept