File tree Expand file tree Collapse file tree 3 files changed +9
-4
lines changed Expand file tree Collapse file tree 3 files changed +9
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
class Dictionary {
4
4
constructor ( ) {
5
- this . map = { } ;
5
+ this . map = Object . create ( null ) ;
6
6
}
7
7
set ( key , value ) {
8
8
return this . map [ key ] = value ;
@@ -11,7 +11,7 @@ class Dictionary {
11
11
return this . map [ key ] ;
12
12
}
13
13
has ( key ) {
14
- return this . map . hasOwnProperty ( key ) ;
14
+ return ! ! this . map [ key ] ;
15
15
}
16
16
delete ( key ) {
17
17
delete this . map [ key ] ;
@@ -23,7 +23,7 @@ class Dictionary {
23
23
return Object . keys ( this . map ) ;
24
24
}
25
25
clear ( ) {
26
- this . map = { } ;
26
+ this . map = Object . create ( null ) ;
27
27
}
28
28
}
29
29
Original file line number Diff line number Diff line change @@ -18,4 +18,4 @@ if (!cityPopulation.has('Shanghai')) {
18
18
}
19
19
20
20
console . log ( 'size:' , cityPopulation . size ) ;
21
- console . log ( 'keys:' , cityPopulation . keys ( ) ) ;
21
+ console . log ( 'keys:' , [ ... cityPopulation . keys ( ) ] ) ;
Original file line number Diff line number Diff line change @@ -20,8 +20,13 @@ const buildIndex = (ds, col) => {
20
20
// Usage
21
21
22
22
const dataset = getDataset ( './cities.dat' ) ;
23
+ console . log ( dataset ) ;
24
+
23
25
const byName = buildIndex ( dataset , 0 ) ;
26
+ console . log ( byName ) ;
27
+
24
28
const byPopulation = buildIndex ( dataset , 1 ) ;
29
+ console . log ( byPopulation ) ;
25
30
26
31
const delhi = byName . get ( 'Delhi' ) ;
27
32
console . log ( delhi ) ;
You can’t perform that action at this time.
0 commit comments