We wrote a function to divide two integers, but it turned out to be unsafe with zero arguments. Refactor the function using Either and return Division by 0 for problematic arguments.
Nullability
How to deal with zero?
Report a typo
Sample Input 1:
8
0Sample Output 1:
Left(Division by 0)Write a program in Scala 3
def safeDivide(x: Int, y: Int): Int =
(x / y)
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.