Find the slope of the given number | function to find slope of a number ; to store slope of the given number ' num ' ; loop from the 2 nd digit up to the 2 nd last digit of the given number ' num ' ; if the digit is a maxima ; if the digit is a minima ; required slope ; Driver code
function slopeOfNum ( num , n ) { let slope = 0 ; for ( let i = 1 ; i < n - 1 ; i ++ ) { if ( num [ i ] > num [ i - 1 ] && num [ i ] > num [ i + 1 ] ) slope ++ ; else if ( num [ i ] < num [ i - 1 ] && num [ i ] < num [ i + 1 ] ) slope ++ ; } return slope ; } let num = " " ; let n = num . length ; document . write ( " " + slopeOfNum ( num , n ) ) ;