count the B ( blue ) colour
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 ; }