Take into account all the substrings
let a2 = new Map ( ) ; for ( let s = 0 ; s < a1 . length ; s ++ ) { if ( a2 . has ( a1 [ s ] ) ) a2 . set ( a1 [ s ] , a2 . get ( a1 [ s ] ) + 1 ) ; else a2 . set ( a1 [ s ] , 1 ) ; } let freshlist = [ ] ;