Count changes in Led Lights to display digits one by one | javascript program to count number of on offs to display digits of a number . ; store the led lights required to display a particular number . ; compute the change in led and keep on adding the change ; Driver code
function countOnOff ( n ) { var Led = [ 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 5 ] ; var len = n . length ; var sum = Led [ n . charAt ( 0 ) - ' ' ] ; for ( i = 1 ; i < len ; i ++ ) { sum = sum + Math . abs ( Led [ n . charAt ( i ) - ' ' ] - Led [ n . charAt ( i - 1 ) - ' ' ] ) ; } return sum ; } n = " " ; document . write ( countOnOff ( n ) ) ;