Lynch | Function to check the divisibility of the number by its digit . ; If the digit divides the number then return true else return false . ; Function to check if all digits of n divide it or not ; Taking the digit of the number into digit var . ; Function to check if N has all distinct digits ; Create an array of size 10 and initialize all elements as false . This array is used to check if a digit is already seen or not . ; Traverse through all digits of given number ; Find the last digit ; If digit is already seen , return false ; Mark this digit as seen ; REmove the last digit from number ; Function to check Lynch - Bell numbers ; Given Number N ; Function Call
function checkDivisibility ( n , digit ) { return ( digit != 0 && n % digit == 0 ) ; } function isAllDigitsDivide ( n ) { let temp = n ; while ( temp > 0 ) { let digit = temp % 10 ; if ( ! ( checkDivisibility ( n , digit ) ) ) return false ; temp = parseInt ( temp / 10 ) ; } return true ; } function isAllDigitsDistinct ( n ) { let arr = Array ( 10 ) . fill ( 0 ) ; while ( n > 0 ) { let digit = n % 10 ; if ( arr [ digit ] ) return false ; arr [ digit ] = true ; n = parseInt ( n / 10 ) ; } return true ; } function isLynchBell ( n ) { return isAllDigitsDivide ( n ) && isAllDigitsDistinct ( n ) ; } let N = 12 ; if ( isLynchBell ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;