Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That task here is: A 'compute-slopes' function gets a list of points and returns a list of slops between consecutive points.

The problem: What if points have the same x-value, hence the slope is undefined.

Solution 1 Exceptions: throw new DivisionByZero()

Solution 2 Condition Handling: provide the restarts point to (a) return nil, (b) return 0, and (c) return a user-specified value.

Solution 3 Return Error: return Error("division by zero")



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: