Program to replace a word with asterisks in a sentence | Function takes two parameter ; Break down sentence by ' ▁ ' spaces and store each individual word in a different list ; A new string to store the result ; Creating the censor which is an asterisks " * " text of the length of censor word ; Iterating through our list of extracted words ; changing the censored word to created asterisks censor ; join the words ; Driver code
function censor ( text , word ) { var word_list = text . split ( " " ) ; var result = " " ; var stars = " " ; for ( var i = 0 ; i < word . length ; i ++ ) stars += " " ; var index = 0 ; for ( const i of word_list ) { if ( i === word ) word_list [ index ] = stars ; index ++ ; } for ( const i of word_list ) { result += i + " " ; } return result ; } var extract = " " + " " + " " ; var cen = " " ; document . write ( censor ( extract , cen ) + " " ) ;