File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,12 +30,16 @@ function Dictionary() {
3030 return items ;
3131 } ;
3232
33- this . size = function ( ) { } ;
33+ // to return the size of the array, you calculate the size of all the keys
34+ this . size = function ( ) {
35+ return Object . keys ( items ) . length ;
36+ } ;
3437
3538 this . keys = function ( ) {
3639 return Object . keys ( items ) ;
3740 } ;
3841
42+ // to return an array of values only, iterate through all items and access values via the keys
3943 this . values = function ( ) {
4044 var values = [ ] ;
4145 for ( var k in items ) {
@@ -53,7 +57,6 @@ var dict = new Dictionary();
5357dict . set ( 'Bucky' , 'bucky@hotmail.com' ) ;
5458dict . set ( 'Sally' , 'sally@gmail.com' ) ;
5559dict . set ( 'Tuna' , 'tuna@aol.com' ) ;
56-
5760console . log ( dict . keys ( ) ) ;
5861console . log ( dict . values ( ) ) ;
5962console . log ( dict . get ( 'Bucky' ) ) ;
@@ -67,3 +70,4 @@ console.log(dict.values());
6770console . log ( '----------' ) ;
6871
6972console . log ( dict . getItems ( ) ) ;
73+ console . log ( dict . size ( ) ) ;
Original file line number Diff line number Diff line change 1+ # Graphs
2+
3+ Description
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+
Original file line number Diff line number Diff line change 11# Sets
22
3- Description
3+ Sets are iterable objects that do not allow for duplicate values.
Original file line number Diff line number Diff line change 1+ # Trees
2+
3+ Description
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+
You can’t perform that action at this time.
0 commit comments