Scala

Scala

Made by DeepSource

Oddness check i % 2 == 0 fails for -ve numbers SC-W1000

Bug risk
Major

Using the standard i % 2 == 0 oddness check fails for -ve numbers. The preferred way is: i % 2 != 0 since +ve numbers leave +1 as remainder and -ve numbers leave -1 as remainder.

Bad Practice

val isOdd = i % 2 == 0

Recommended

val isOdd = i % 2 != 0