text: Remove all the palindromic words from the given sentence | function to check if ' str ' is palindrome ; traversing from both the ends ; not palindrome ; palindrome ; function to remove all the palindromic words from the given sentence ; ' final _ str ' to store the final string and ' word ' to one by one store each word of ' str ' ; add space at the end of ' str ' ; traversing ' str ' ; accumulating characters of the current word ; if ' word ' is not palindrome then a add it to ' final _ str ' ; reset ; required final string ; Driver program to test above
code: function isPalindrome ( str ) { var i = 0 , j = str . length - 1 ; while ( i < j ) if ( str [ i ++ ] != str [ j -- ] ) return false ; return true ; } function removePalinWords ( str ) { var final_str = " " , word = " " ; str = str + " " ; var n = str . length ; for ( var i = 0 ; i < n ; i ++ ) { if ( str [ i ] != ' ' ) word = word + str [ i ] ; else { if ( ! ( isPalindrome ( word ) ) ) final_str += word + " " ; word = " " ; } } return final_str ; } var str = " " ; document . write ( removePalinWords ( str ) ) ;