리팩터링
extract-method1
outstanding을 this.getTotalOutStanding()으로 처리하는 것이 아닌,
outstanding을 파라미터로 받아서 결과 출력
public printOwing() {
this.printLogText();
this.printCustomerOwe(this.getTotalOutStanding());
}
private printCustomerOwe(outstanding: number) {
console.log("name : " + this.name);
console.log("amount : " + outstanding);
}
- B메서드 구현방법 : for문으로 구현 / reduce로 구현
//reduce
private getOutstanding) {
return this.amounds.reduce((acc, cur) = acc + cur, 0);
}
//for
private getOutstanding(amounts: Array<number>) {
let result: number = 0;
for (let amount of amounts) {
result += amount;
}
return result;
}
2번 - extract method2
- 가독성(include) : 조건별 include 사용해서 확인
- 성능(for) : for문 한번에 모든 조건 확인
//include
private hasStar0rQuestionMark(path: string) {
return path.includes("?") || path.includes("*")
}
private hasSortedOpenAndCloseBracket(path: string) {
return path.includes("{") && path.include("{") < path.indexof("}");
//for
for (let i = 0; i < path.length; i++) {
let c = path.charAt(i);
if (c == '*' || c == '?') {
return true;
}
if (c == '{') {
uriVar = true;
continue;
}
if (c == '}' && uriVar) {
return true;
}
}
다음 스터디에서 확인할 내용
- test 돌렸을 때 결과 duration 두개 나오는데 어떤 차이인지?
- 정규표현식으로 2번 해결할 수 있을지
public isPattern(path: string): boolean {
// this.hasSpecialAlphabet(path);
if (/[*?]/.test(path) || /.*[{].*[}].*/.test(path)) return true;
return false;
}
'스터디일지' 카테고리의 다른 글
[스터디일지] 23.01.08 (0) | 2023.01.14 |
---|---|
221225 개발 스터디 기록 (0) | 2022.12.31 |