interface ISortedMap < K , V > { clear ( ) : void ; delete ( key ) : boolean ; forEach ( callbackfn , thisArg ? ) : void ; get ( key ) : V | undefined ; has ( key ) : boolean ; set ( key , value ) : Map < K , V > ; size ( ) : number ; map : ( callbackfn : ( value : [ K , V ] , index : number , array : [ K , V ] [ ] ) => any , thisArg ? : any ) => any [ ] ; iterator : Map < K , V > ; } export function SortedMap < K , V > ( comparator ) { const obj = new Map < K , V > ( ) ; obj [ Symbol . iterator ] = function * ( ) { yield * [ ... this . entries ( ) ] . sort ( comparator ) ; } ; return { size : ( ) => obj . size , clear : ( ) => obj . clear ( ) , delete : ( key ) => obj . delete ( key ) , forEach : ( callbackfn , thisArg ? ) => obj . forEach ( callbackfn , thisArg ) , get : ( key ) => obj . get ( key ) , has : ( key ) => obj . has ( key ) , set : ( key , value ) => obj . set ( key , value ) , map : ( callbackfn , thisArg ? ) => { return [ ... obj ] . map ( callbackfn , thisArg ) ; } , iterator : obj } ; }