Replace Nested Conditional with Guard Clauses
Before Code [code language=”ruby”] def getGrade(score) if score >= 80 return "A" elsif score >=70 return "B" elsif score >=60 return "C" elsif score >= 50 return "D" else return "F" end end [/code] After Code [code language=”ruby”] def getGrade(score) return "A" if score >= 80 return "B" if score >= 70 return "C" if […]
Replace Nested Conditional with Guard Clauses Read More »