4
4
* @for p5.TypedDict
5
5
* @requires core
6
6
*
7
- * This module defines the p5 methods for the p5 Dictionary classes
8
- * these classes StringDict and NumberDict are for storing and working
9
- * with key, value pairs
7
+ * This module defines the p5 methods for the p5 Dictionary classes.
8
+ * The classes StringDict and NumberDict are for storing and working
9
+ * with key- value pairs.
10
10
*/
11
11
12
12
'use strict' ;
@@ -15,8 +15,8 @@ var p5 = require('../core/core');
15
15
16
16
/**
17
17
*
18
- * Creates a new instance of p5.StringDict using the key, value pair
19
- * or object you provide.
18
+ * Creates a new instance of p5.StringDict using the key- value pair
19
+ * or the object you provide.
20
20
*
21
21
* @method createStringDict
22
22
* @for p5
@@ -30,6 +30,9 @@ var p5 = require('../core/core');
30
30
* function setup() {
31
31
* var myDictionary = createStringDict('p5', 'js');
32
32
* print(myDictionary.hasKey('p5')); // logs true to console
33
+ *
34
+ * var anotherDictionary = createStringDict({ happy: 'coding' });
35
+ * print(anotherDictionary.hasKey('happy')); // logs true to console
33
36
* }
34
37
* </code></div>
35
38
*/
@@ -46,7 +49,7 @@ p5.prototype.createStringDict = function(key, value) {
46
49
47
50
/**
48
51
*
49
- * Creates a new instance of p5.NumberDict using the key, value pair
52
+ * Creates a new instance of p5.NumberDict using the key- value pair
50
53
* or object you provide.
51
54
*
52
55
* @method createNumberDict
@@ -61,6 +64,9 @@ p5.prototype.createStringDict = function(key, value) {
61
64
* function setup() {
62
65
* var myDictionary = createNumberDict(100, 42);
63
66
* print(myDictionary.hasKey(100)); // logs true to console
67
+ *
68
+ * var anotherDictionary = createNumberDict({ 200: 84 });
69
+ * print(anotherDictionary.hasKey(200)); // logs true to console
64
70
* }
65
71
* </code></div>
66
72
*/
@@ -77,8 +83,8 @@ p5.prototype.createNumberDict = function(key, value) {
77
83
78
84
/**
79
85
*
80
- * Base class for all p5.Dictionary types. More specifically
81
- * typed Dictionary objects inherit from this
86
+ * Base class for all p5.Dictionary types. Specifically
87
+ * typed Dictionary classes inherit from this class.
82
88
*
83
89
* @class p5.TypedDict
84
90
*
@@ -95,10 +101,10 @@ p5.TypedDict = function(key, value) {
95
101
} ;
96
102
97
103
/**
98
- * Returns the number of key-value pairs currently in Dictionary object
104
+ * Returns the number of key-value pairs currently stored in the Dictionary.
99
105
*
100
106
* @method size
101
- * @return {Integer } the number of key-value pairs in Dictionary object
107
+ * @return {Integer } the number of key-value pairs in the Dictionary
102
108
*
103
109
* @example
104
110
* <div class="norender">
@@ -107,7 +113,7 @@ p5.TypedDict = function(key, value) {
107
113
* var myDictionary = createNumberDict(1, 10);
108
114
* myDictionary.create(2, 20);
109
115
* myDictionary.create(3, 30);
110
- * print(myDictionary.size()); // value of amt is 3
116
+ * print(myDictionary.size()); // logs 3 to the console
111
117
* }
112
118
* </code></div>
113
119
*
@@ -117,11 +123,11 @@ p5.TypedDict.prototype.size = function() {
117
123
} ;
118
124
119
125
/**
120
- * Returns true if key exists in Dictionary
121
- * otherwise returns false
126
+ * Returns true if the given key exists in the Dictionary,
127
+ * otherwise returns false.
122
128
*
123
129
* @method hasKey
124
- * @param {Number|String } key that you want to access
130
+ * @param {Number|String } key that you want to look up
125
131
* @return {Boolean } whether that key exists in Dictionary
126
132
*
127
133
* @example
@@ -140,10 +146,10 @@ p5.TypedDict.prototype.hasKey = function(key) {
140
146
} ;
141
147
142
148
/**
143
- * Returns value stored at supplied key.
149
+ * Returns the value stored at the given key.
144
150
*
145
151
* @method get
146
- * @param {Number|String } key that you want to access
152
+ * @param {Number|String } the key you want to access
147
153
* @return {Number|String } the value stored at that key
148
154
*
149
155
* @example
@@ -167,8 +173,8 @@ p5.TypedDict.prototype.get = function(key) {
167
173
} ;
168
174
169
175
/**
170
- * Changes the value of key if in it already exists in
171
- * in the Dictionary otherwise makes a new key-value pair
176
+ * Updates the value associated with the given key in case it already exists
177
+ * in the Dictionary. Otherwise a new key-value pair is added.
172
178
*
173
179
* @method set
174
180
* @param {Number|String } key
@@ -180,8 +186,7 @@ p5.TypedDict.prototype.get = function(key) {
180
186
* function setup() {
181
187
* var myDictionary = createStringDict('p5', 'js');
182
188
* myDictionary.set('p5', 'JS');
183
- * myDictionary.print();
184
- * // above logs "key: p5 - value: JS" to console
189
+ * myDictionary.print(); // logs "key: p5 - value: JS" to console
185
190
* }
186
191
* </code></div>
187
192
*
@@ -196,7 +201,7 @@ p5.TypedDict.prototype.set = function(key, value) {
196
201
} ;
197
202
198
203
/**
199
- * private helper function to handle the user passing objects in
204
+ * private helper function to handle the user passing in objects
200
205
* during construction or calls to create()
201
206
*/
202
207
@@ -207,7 +212,7 @@ p5.TypedDict.prototype._addObj = function(obj) {
207
212
} ;
208
213
209
214
/**
210
- * Creates a key-value pair in the Dictionary
215
+ * Creates a new key-value pair in the Dictionary.
211
216
*
212
217
* @method create
213
218
* @param {Number|String } key
@@ -243,7 +248,8 @@ p5.TypedDict.prototype.create = function(key, value) {
243
248
} ;
244
249
245
250
/**
246
- * Empties Dictionary of all key-value pairs
251
+ * Removes all previously stored key-value pairs from the Dictionary.
252
+ *
247
253
* @method clear
248
254
* @example
249
255
* <div class="norender">
@@ -263,7 +269,7 @@ p5.TypedDict.prototype.clear = function() {
263
269
} ;
264
270
265
271
/**
266
- * Removes a key-value pair in the Dictionary
272
+ * Removes the key-value pair stored at the given key from the Dictionary.
267
273
*
268
274
* @method remove
269
275
* @param {Number|String } key for the pair to remove
@@ -293,7 +299,7 @@ p5.TypedDict.prototype.remove = function(key) {
293
299
} ;
294
300
295
301
/**
296
- * Logs the list of items currently in the Dictionary to the console
302
+ * Logs the set of items currently stored in the Dictionary to the console.
297
303
*
298
304
* @method print
299
305
*
@@ -317,8 +323,7 @@ p5.TypedDict.prototype.print = function() {
317
323
} ;
318
324
319
325
/**
320
- * Converts the Dictionary into a CSV file for local
321
- * storage.
326
+ * Converts the Dictionary into a CSV file for local download.
322
327
*
323
328
* @method saveTable
324
329
* @example
@@ -329,9 +334,9 @@ p5.TypedDict.prototype.print = function() {
329
334
* .mousePressed(function() {
330
335
* createStringDict({
331
336
* john: 1940,
332
- paul: 1942,
333
- george: 1943,
334
- ringo: 1940
337
+ * paul: 1942,
338
+ * george: 1943,
339
+ * ringo: 1940
335
340
* }).saveTable('beatles');
336
341
* });
337
342
* </code>
@@ -350,8 +355,7 @@ p5.TypedDict.prototype.saveTable = function(filename) {
350
355
} ;
351
356
352
357
/**
353
- * Converts the Dictionary into a JSON file for local
354
- * storage.
358
+ * Converts the Dictionary into a JSON file for local download.
355
359
*
356
360
* @method saveJSON
357
361
* @example
@@ -362,9 +366,9 @@ p5.TypedDict.prototype.saveTable = function(filename) {
362
366
* .mousePressed(function() {
363
367
* createStringDict({
364
368
* john: 1940,
365
- paul: 1942,
366
- george: 1943,
367
- ringo: 1940
369
+ * paul: 1942,
370
+ * george: 1943,
371
+ * ringo: 1940
368
372
* }).saveJSON('beatles');
369
373
* });
370
374
* </code>
@@ -386,8 +390,7 @@ p5.TypedDict.prototype._validate = function(value) {
386
390
387
391
/**
388
392
*
389
- * A Dictionary class for Strings.
390
- *
393
+ * A simple Dictionary class for Strings.
391
394
*
392
395
* @class p5.StringDict
393
396
* @extends p5.TypedDict
@@ -408,7 +411,6 @@ p5.StringDict.prototype._validate = function(value) {
408
411
*
409
412
* A simple Dictionary class for Numbers.
410
413
*
411
- *
412
414
* @class p5.NumberDict
413
415
* @extends p5.TypedDict
414
416
*
@@ -430,19 +432,19 @@ p5.NumberDict.prototype._validate = function(value) {
430
432
} ;
431
433
432
434
/**
433
- * Add to a value stored at a certain key
434
- * The sum is stored in that location in the Dictionary.
435
+ * Add the given number to the value currently stored at the given key.
436
+ * The sum then replaces the value previously stored in the Dictionary.
435
437
*
436
438
* @method add
437
- * @param {Number } Key for value you wish to add to
438
- * @param {Number } Amount to add to the value
439
+ * @param {Number } Key for the value you wish to add to
440
+ * @param {Number } Number to add to the value
439
441
* @example
440
442
* <div class='norender'>
441
443
* <code>
442
444
* function setup() {
443
445
* var myDictionary = createNumberDict(2, 5);
444
446
* myDictionary.add(2, 2);
445
- * console.log (myDictionary.get(2)); // logs 7 to console.
447
+ * print (myDictionary.get(2)); // logs 7 to console.
446
448
* }
447
449
* </code></div>
448
450
*
@@ -458,19 +460,19 @@ p5.NumberDict.prototype.add = function(key, amount) {
458
460
} ;
459
461
460
462
/**
461
- * Subtract from a value stored at a certain key
462
- * The difference is stored in that location in the Dictionary.
463
+ * Subtract the given number from the value currently stored at the given key.
464
+ * The difference then replaces the value previously stored in the Dictionary.
463
465
*
464
466
* @method sub
465
- * @param {Number } Key for value you wish to subtract from
466
- * @param {Number } Amount to subtract from the value
467
+ * @param {Number } Key for the value you wish to subtract from
468
+ * @param {Number } Number to subtract from the value
467
469
* @example
468
470
* <div class='norender'>
469
471
* <code>
470
472
* function setup() {
471
473
* var myDictionary = createNumberDict(2, 5);
472
474
* myDictionary.sub(2, 2);
473
- * console.log (myDictionary.get(2)); // logs 3 to console.
475
+ * print (myDictionary.get(2)); // logs 3 to console.
474
476
* }
475
477
* </code></div>
476
478
*
@@ -482,8 +484,8 @@ p5.NumberDict.prototype.sub = function(key, amount) {
482
484
} ;
483
485
484
486
/**
485
- * Multiply a value stored at a certain key
486
- * The product is stored in that location in the Dictionary.
487
+ * Multiply the given number with the value currently stored at the given key.
488
+ * The product then replaces the value previously stored in the Dictionary.
487
489
*
488
490
* @method mult
489
491
* @param {Number } Key for value you wish to multiply
@@ -494,7 +496,7 @@ p5.NumberDict.prototype.sub = function(key, amount) {
494
496
* function setup() {
495
497
* var myDictionary = createNumberDict(2, 4);
496
498
* myDictionary.mult(2, 2);
497
- * console.log (myDictionary.get(2)); // logs 8 to console.
499
+ * print (myDictionary.get(2)); // logs 8 to console.
498
500
* }
499
501
* </code></div>
500
502
*
@@ -510,8 +512,8 @@ p5.NumberDict.prototype.mult = function(key, amount) {
510
512
} ;
511
513
512
514
/**
513
- * Divide a value stored at a certain key
514
- * The quotient is stored in that location in the Dictionary.
515
+ * Divide the given number with the value currently stored at the given key.
516
+ * The quotient then replaces the value previously stored in the Dictionary.
515
517
*
516
518
* @method div
517
519
* @param {Number } Key for value you wish to divide
@@ -522,7 +524,7 @@ p5.NumberDict.prototype.mult = function(key, amount) {
522
524
* function setup() {
523
525
* var myDictionary = createNumberDict(2, 8);
524
526
* myDictionary.div(2, 2);
525
- * console.log (myDictionary.get(2)); // logs 4 to console.
527
+ * print (myDictionary.get(2)); // logs 4 to console.
526
528
* }
527
529
* </code></div>
528
530
*
@@ -561,7 +563,7 @@ p5.NumberDict.prototype._valueTest = function(flip) {
561
563
} ;
562
564
563
565
/**
564
- * Return the lowest value .
566
+ * Return the lowest number currently stored in the Dictionary .
565
567
*
566
568
* @method minValue
567
569
* @return {Number }
@@ -582,7 +584,7 @@ p5.NumberDict.prototype.minValue = function() {
582
584
} ;
583
585
584
586
/**
585
- * Return the highest value .
587
+ * Return the highest number currently stored in the Dictionary .
586
588
*
587
589
* @method maxValue
588
590
* @return {Number }
@@ -626,7 +628,7 @@ p5.NumberDict.prototype._keyTest = function(flip) {
626
628
} ;
627
629
628
630
/**
629
- * Return the lowest key.
631
+ * Return the lowest key currently used in the Dictionary .
630
632
*
631
633
* @method minKey
632
634
* @return {Number }
@@ -647,7 +649,7 @@ p5.NumberDict.prototype.minKey = function() {
647
649
} ;
648
650
649
651
/**
650
- * Return the highest key.
652
+ * Return the highest key currently used in the Dictionary .
651
653
*
652
654
* @method maxKey
653
655
* @return {Number }
0 commit comments