2회차 스터디 후 src/1week 리팩터링하기 #1
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TL;DR
Description
01.js
전역 변수를 사용하는
암묵적 입력을 인자로 옮겨명시적 입력으로 전환했습니다.그리고 그러면 해당 함수를 사용하는 곳에서 인수를 작성해야하는 상황이되는데 이를 막고자
기본값 매개변수를 활용하여 동작에 변경이 없도록 하였습니다.02.js
계산함수 분리하기에 해당한다고 생각되어 배열요소를 알아야하는 부분과 아닌 부분을 분리하였습니다.
만약 배열요소의 구조가 변경되면 sum 함수만 변경하는 이점을 갖습니다.
03.js
조건문은 언제든 변할 수 있고 어디서든 동일하게 적용할 수 있다고 생각되어 계산으로 추출했습니다.
아쉬운 점은 multiDimensionalAccmulate 함수가 배열을 이중으로 순회하고 있는데 이를 한번 순회하는 함수를 중첩해서 사용하는 식으로 빼내보고 싶었습니다. 즉, 사용하는 곳에서 이중 배열이든 이중 객체든 신경안써도 되는 형태로 구현하고 싶었습니다.
04.js
계산에서 더 낮은 계산식으로 추출했습니다.
그리고 변경될 수 있는 비즈니스 조건을 계산으로 추출했습니다.
05.js