Remainder with 7 for large numbers | Function which returns Remainder after dividing the number by 7 ; This series is used to find remainder with 7 ; Index of next element in series ; Traverse num from end ; Find current digit of nun ; Add next term to result ; Move to next term in series ; Make sure that result never goes beyond 7. ; Make sure that remainder is positive ; Driver program
function remainderWith7 ( num ) { series = [ 1 , 3 , 2 , - 1 , - 3 , - 2 ] var series_index = 0 ; for ( var i = num . length - 1 ; i >= 0 ; i -- ) { var digit = num [ i ] - ' ' ; result += digit * series [ series_index ] ; series_index = ( series_index + 1 ) % 6 ; result %= 7 ; } if ( result < 0 ) result = ( result + 7 ) % 7 ; return result ; } var str = " " ; document . write ( " " + remainderWith7 ( str ) ) ;