Coding Challenge: Using Option in Function

Let's use Option monad in a function in this coding challenge.

Problem statement

Write a function called safeDivide that takes two parameters called value and divisor, both of type number. If the divisor isn’t equal to 0, the function divides the value by the divisor and returns the result wrapped in an option. Otherwise, the function returns an empty optional.

Try it yourself

Get hands-on with 1200+ tech skills courses.