얌마들아 그런건 그렇게 하면 안돼지
대략 아래처럼 로직이랑 데이터를 완벽히 분리해야 한다. 이를테면 아래있는 get-tax-rates는 데이터베이스 쿼리로 대치할 수 잇겠지. 그래야 나중에 국세청에서 세율을 바꿔도 코드는 안바꾸고 데이터만 바꿔서 쓸수 있는거지.
뭐 이런거 알려줘도 갤에 이해하는 생키들 몇 있겠냐마는, 밥먹고 할일없어서 심심풀이 땅콩으로 한번 싸줌 ㅎㅎ
(def tax-rates [{:min 0 :max 10000000 :rate 0.08}
{:min 10000000 :max 40000000 :rate 0.17}
{:min 40000000 :max 80000000 :rate 0.26}
{:min 80000000 :max nil :rate 0.35}])
(defn get-tax-rates []
(sort #(> (:min %1 ) (:min %2)) tax-rates))
(defn compute-income-tax [amount]
(loop [[{:keys [min max rate]} & more-rates] (get-tax-rates)
amount amount
result 0]
(cond (nil? min) result
(< amount min)
(recur more-rates amount result)
:else (let [amount-diff (- amount min)]
(recur more-rates
(- amount amount-diff)
(+ result (* amount-diff rate)))))))
누진세가 뭔지도 모르는 애한테 저런걸 설명하면 알아듣냐. 일단 만드는 법 알고 나서 저걸 배워야지. 내가 처음에 한 설명 중에 틀린게 있어서 지웠는데, 최적화도 언급했었다. 근데 갓 걸음마 하는 애기한테, 마라톤 뛰는 요령 알려주면 알아듣냐고.
십생키
^ㅇ^