@@ -9,26 +9,31 @@ class Map<TKey, TValue> {
99
1010 if ( other ) {
1111 this . size = other . size ;
12- other . forEach ( ( value , key ) => { this . items [ key ] = value ; } ) ;
12+ for ( const [ key , value ] of other . entries ( ) ) {
13+ this . items [ key ] = value ;
14+ }
1315 }
1416 }
1517
1618 public clear ( ) : void {
1719 this . items = { } ;
1820 this . size = 0 ;
21+ return ;
1922 }
2023
2124 public delete ( key : TKey ) : boolean {
2225 const contains = this . has ( key ) ;
26+ if ( contains ) {
27+ this . size = this . size - 1 ;
28+ }
2329 this . items [ key as any ] = undefined ;
24- this . size = this . size - 1 ;
2530 return contains ;
2631 }
2732
2833 public entries ( ) : Array < [ TKey , TValue ] > {
2934 const out = [ ] ;
3035 for ( const key in this . items ) {
31- out [ out . length + 1 ] = [ key , this . items [ key ] ] ;
36+ out [ out . length ] = [ key , this . items [ key ] ] ;
3237 }
3338 return out ;
3439 }
@@ -37,20 +42,21 @@ class Map<TKey, TValue> {
3742 for ( const key in this . items ) {
3843 callback ( this . items [ key ] , key as any , this ) ;
3944 }
45+ return ;
4046 }
4147
4248 public get ( key : TKey ) : TValue {
4349 return this . items [ key as any ] ;
4450 }
4551
4652 public has ( key : TKey ) : boolean {
47- return this . items [ key as any ] != undefined ;
53+ return this . items [ key as any ] !== undefined ;
4854 }
4955
5056 public keys ( ) : TKey [ ] {
5157 const out = [ ] ;
5258 for ( const key in this . items ) {
53- out [ out . length + 1 ] = key ;
59+ out [ out . length ] = key ;
5460 }
5561 return out ;
5662 }
@@ -66,7 +72,7 @@ class Map<TKey, TValue> {
6672 public values ( ) : TValue [ ] {
6773 const out = [ ] ;
6874 for ( const key in this . items ) {
69- out [ out . length + 1 ] = this . items [ key ] ;
75+ out [ out . length ] = this . items [ key ] ;
7076 }
7177 return out ;
7278 }
0 commit comments