Clean Code
๐ Junior Vs Senior Code - How To Write Better Code๋ฅผ ๋ณด๊ณ ์ ๋ฆฌํ ๋ด์ฉ์ ๋๋ค.
1. Logic(๋ก์ง)
Step 1๏ธโฃ
// ๋งค๊ฐ๋ณ์๊ฐ ์์์ผ ๋ ์ธ์ ์์์ ๊ดํธ ํจ๊ป ๋ฐํํ๋ ํจ์
// step 1
function toAccount(n) {
if(n < 0) {
return '(' + Math.abs(n) + ')'
} else if(n >= 0) {
return n
}
}Step 2๏ธโฃ
// step 2
// ํจ์๋ช
๊ณผ ๋ณ์๋ช
์์
function numberToAccountingString(number) {
// undefined, null ๊ณ ๋ ค
if(number !== null) {
if(number < 0) {
// template literal
return `(${Math.abs(number)})` // 4) ํ์
- ๋ฌธ์์ด
} else {
return number.toString() // ํ์
- ๋ฌธ์์ด
}
}
}
console.log(numberToAccountingString(undefined))Step 3๏ธโฃ
2. Variable Manipulation(๋งค๊ฐ๋ณ์ ์กฐ์)
Step 1๏ธโฃ
Step 2๏ธโฃ
Step 3๏ธโฃ
Last updated