Check if the number is even or odd whose digits and base ( radix ) is given | Function that returns true if the number represented by arr [ ] is even in base r ; If the base is even , then the last digit is checked ; If base is odd , then the number of odd digits are checked ; To store the count of odd digits ; Number is odd ; Driver code
function isEven ( arr , n , r ) { if ( r % 2 == 0 ) { if ( arr [ n - 1 ] % 2 == 0 ) return true ; } else { let oddCount = 0 ; for ( let i = 0 ; i < n ; ++ i ) { if ( arr [ i ] % 2 != 0 ) oddCount ++ ; } if ( oddCount % 2 == 0 ) return true ; } return false ; } let arr = [ 1 , 0 ] ; let n = arr . length ; let r = 2 ; if ( isEven ( arr , n , r ) ) document . write ( " " ) ; else document . write ( " " ) ;