Contiguous subsegments of a string having distinct subsequent characters | Function that prints the segments ; New array for every iteration ; Check if the character is in the array ; Driver code
function sub_segments ( str , n ) { let l = str . length ; for ( let x = 0 ; x < l ; x += n ) { let newlist = str . substr ( x , n ) ; let arr = [ ] ; for ( let y of newlist ) { if ( ! arr . includes ( y ) ) arr . push ( y ) ; } for ( let y of arr ) document . write ( y ) ; document . write ( " " ) ; } } let str = " " ; let n = 4 ; sub_segments ( str , n ) ;