text: Print sorted distinct elements of array | Javascript program to print sorted distinct elements . ; Create a set using array elements ; Print contents of the set . ; Driver code
code: function printRepeating ( arr , size ) { var s = new Set ( arr ) ; [ ... s ] . sort ( ( a , b ) => a - b ) . forEach ( x => { document . write ( x + " " ) } ) ; } var arr = [ 1 , 3 , 2 , 2 , 1 ] ; var n = arr . length ; printRepeating ( arr , n ) ;