compute the change in led and keep on adding the change
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 ; }