Even Digits Only
Check if all digits of the given integer are even.
Example
- For
n = 248622
, the output should be
even_digits_only(n) = true
- For
n = 642386
, the output should be
even_digits_only(n) = false
Solution
py
def even_digits_only(n):
return all(int(i) % 2 == 0 for i in str(n))
print(even_digits_only(248622))
js
function even_digits_only(n) {
return n
.toString()
.split('')
.every((digit) => digit % 2 === 0);
}
console.log(even_digits_only(248622));