Count of ordered triplets ( R , G , B ) in a given original string | function to count the ordered triplets ( R , G , B ) ; count the B ( blue ) colour ; Driver program
function countTriplets ( color ) { var result = 0 , Blue_Count = 0 ; var Red_Count = 0 ; var data = color . split ( ' ' ) ; for ( var i = 0 ; i < data . length ; i ++ ) { if ( data [ i ] == ' ' ) Blue_Count ++ ; } for ( var i = 0 ; i < data . length ; i ++ ) { if ( data [ i ] == ' ' ) Blue_Count -- ; if ( data [ i ] == ' ' ) Red_Count ++ ; if ( data [ i ] == ' ' ) result += Red_Count * Blue_Count ; } return result ; } var color = " " ; document . write ( countTriplets ( color ) ) ;