Closed jpluscplusm closed 3 months ago
It'd be worth checking in on https://github.com/cue-lang/cue/issues/2926 to see if a standard-library-based solution could also be demonstrated.
Closed via https://github.com/cue-lang/cuelang.org/commit/e57cd0ec72701eeb7c62621a14d53cd621f07737, and now published at https://alpha.cuelang.org/docs/howto/validate-integer-value-parity/.
Many thanks for writing this, @noamtd!
Can, of course, be expanded to check for multiples of any integer, not just 2; but the resulting page title would get a little wordy.
This also works:
... but doing the same for
#odd
is more fiddly, as it requires responding to the sign of the original number. i.e. the trailing+1
needs to be-1
if the number is negative. Not /hard/, just inelegant, relative to the first solution, above.