Print all distinct strings from a given array | Function to find the distinct strings from the given array ; Stores distinct strings from the given array ; Traverse the array ; If current string not present into the set ; Insert current string into the set ; Traverse the set DistString ; Print distinct string ; Driver Code ; Stores length of the array
function findDisStr ( arr , N ) { let DistString = new Set ( ) ; for ( let i = N - 1 ; i >= 0 ; i -- ) { if ( ! DistString . has ( arr [ i ] ) ) { DistString . add ( arr [ i ] ) ; } } for ( let String of DistString ) { document . write ( String + " " ) ; } } let arr = [ " " , " " , " " , " " , " " ] ; let N = arr . length ; findDisStr ( arr , N ) ;