-
I did this: if (x.mod(2).eq(BigNumber.from(0))) {
// Even number
} else {
// Odd number
} But it feels somewhat verbose. Is there a shorter/ neater way? |
Beta Was this translation helpful? Give feedback.
Answered by
ricmoo
May 17, 2021
Replies: 1 comment 1 reply
-
Keep in mind But either of these is prolly better:
Hope that helps. :) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
PaulRBerg
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Keep in mind
==
doesn't work on BigNumbers, you would needx.mod(2).eq(BigNumber.from(0))
.But either of these is prolly better:
x.mod(2).isZero()
x.mod(2).eq(0)
x.and(1).isZero()
x.and(1).eq(0)
Hope that helps. :)