@@ -65,6 +65,8 @@ getPublicArray(array = []): PublicArray
65
65
66
66
## Properties with methods
67
67
68
+ Helpful tidbit: These properties all contain their own ` .data ` property, which always matches ` this.data `
69
+
68
70
#### filter: PublicArrayFilter (read-only)
69
71
###### Its methods narrow down the content of this.data and return the PublicArrayFilter instance:
70
72
<details >
@@ -83,7 +85,7 @@ filter.byType(
83
85
84
86
85
87
#### get: PublicArrayGetter (read-only)
86
- ###### Has methods that return items copied from this.data . None of them modify the array .
88
+ ###### Its methods return items copied from this.data . None of them modify this.data .
87
89
<details >
88
90
<summary >view methods</summary >
89
91
@@ -98,21 +100,21 @@ get.byIndexes(indexes): any[]
98
100
// Returns items identified by passed indexes. indexes can be negative or positive.
99
101
100
102
get.head(numItems): any[]
101
- // returns numItems from beginning
103
+ // returns numItems from beginning of this.data
102
104
103
105
get.tail(numItems): any[]
104
- // returns numItems from end
106
+ // returns numItems from end of this.data
105
107
106
108
get.between(numItemsToIgnoreAtEachEnd): any[]
107
- // Returns middle of array , between numItemsToIgnoreAtEachEnd
109
+ // Returns middle of this.data , between numItemsToIgnoreAtEachEnd
108
110
109
111
get.adjacentAt(startingIndex, numItemsToGet): any[]
110
112
// Returns adjacent items. startingIndex can be negative or positive.
111
113
112
114
get.adjacentToValue(info: IAdjacentToValueInfo): any[]
113
115
/**************
114
116
Returns adjacent items including, or near, a particular value.
115
- Only applies to the first instance of value found in array .
117
+ Only applies to the first instance of value found in this.data .
116
118
The parameter 'info' is an object that looks like this:
117
119
{
118
120
value: any except object (the value to search for in the array),
@@ -147,42 +149,45 @@ get.duplicates(): any[]
147
149
// returns every instance of a duplicate, so you may get multiple instances.
148
150
149
151
get.shuffled(): any[]
150
- // returns new version of the array with the order of items randomized.
152
+ // returns copy of this.data with the order of items randomized.
153
+
154
+ /************
155
+ These last 2 methods both return an array of IValueIndexPairs. A IValueIndexPair looks like this:
156
+ {value: any, index: number}
157
+
158
+ Each one represents an item from this.data .
159
+ ************/
151
160
152
161
get.byTest(testFunction: ((currentValue, currentIndex?, array?) => boolean)): IValueIndexPair[]
153
- /***************
154
- Almost exactly like Array.filter(), except it returns array of IValueIndexPairs.
155
- A IValueIndexPair is this object: {value: any, index: integer}
156
- It's both the value filtered by the testFunction and its index.
157
- ***************/
162
+ // returns any item that passes testFunction.
158
163
159
164
get.byType(
160
165
type: 'object' | 'array' | 'number' | 'string' | 'boolean' | 'function' | 'undefined'
161
166
): IValueIndexPair[]
162
- // For explanation of IValueIndexPair, see explanation of get.byTest() .
167
+ // returns any item that is passed type .
163
168
```
164
169
</details >
165
170
166
171
167
172
#### getConverted: PublicArrayGetterConverter (read-only)
168
- ###### Has the Array methods .map() and .reduce() , but renamed to .each() and .toOne() , respectively. None of them modify the array .
173
+ ###### Has the Array methods .map() and .reduce() , but renamed to .each() and .toOne() , respectively. None of them modify this.data .
169
174
<details >
170
175
<summary >view methods</summary >
171
176
172
177
```
173
178
getConverted.toOne(
174
179
reducingFunction: ((previousValue: any, currentValue: any, index?, array?) => any)
175
180
): any
176
- // reduces all values in array down to a single value, and returns that value.
181
+ // reduces all values in this.data down to a single value, and returns that value.
177
182
178
183
getConverted.each(mappingFunction: ((item, index?, array?) => any)): any[]
179
- // returns new array where each value in current array is converted into something else.
184
+ // returns new array where each value in this.data is converted into something else.
180
185
```
181
186
</details >
182
187
183
188
184
189
#### getAndRemove: PublicArrayGetterRemover (read-only)
185
- ###### Has methods that both remove and return items from the array :
190
+ ###### Its methods both remove and return items from this.data :
186
191
<details >
187
192
<summary >view methods</summary >
188
193
@@ -200,15 +205,15 @@ getAndRemove.tail(numItemsToRemove): any[]
200
205
// removes and returns numItemsToRemove from end
201
206
202
207
getAndRemove.between(numItemsToKeepAtEachEnd): any[]
203
- // removes and returns middle of array , between numItemsToKeepAtEachEnd
208
+ // removes and returns middle of this.data , between numItemsToKeepAtEachEnd
204
209
205
210
getAndRemove.adjacentAt(startingIndex, numItemsToRemove): any[]
206
211
// removes and returns adjacent items. startingIndex can be negative or positive.
207
212
208
213
getAndRemove.adjacentToValue(info: IAdjacentToValueInfo): any[]
209
214
/********
210
215
Removes and returns adjacent items including, or near, a particular value.
211
- Only applies to the first instance of value found in array .
216
+ Only applies to the first instance of value found in this.data .
212
217
The parameter 'info' is an object that looks like this:
213
218
{
214
219
value: any except object (the value to search for in the array),
@@ -218,8 +223,8 @@ getAndRemove.adjacentToValue(info: IAdjacentToValueInfo): any[]
218
223
}
219
224
Example:
220
225
// this.data is [1,2,3,4,5,6,7,8,9,10]
221
- let numbers = this.getAndRemove.adjacentToValue({value:5, offset: -2 , howMany:3 });
222
- // numbers is now [3,4,5 ]. this.data is now [1,2,6,7,8 ,9,10]
226
+ let numbers = this.getAndRemove.adjacentToValue({value:5, offset: 0 , howMany:4 });
227
+ // numbers is now [5,6,7,8 ]. this.data is now [1,2,3,4 ,9,10]
223
228
*********/
224
229
225
230
// For all the functions below, the parameter 'value' cannot be object.
@@ -243,23 +248,24 @@ getAndRemove.duplicates(): any[]
243
248
These last 2 methods both return an array of IValueIndexPairs. A IValueIndexPair looks like this:
244
249
{value: any, index: number}
245
250
246
- Each one represents a removed array item .
251
+ Each one represents an item removed from this.data .
247
252
************/
248
253
249
254
getAndRemove.byTest(
250
255
testFunction: (currentValue, currentIndex?, array?) => boolean
251
256
): IValueIndexPair[]
252
- // removes and returns any value that passes test .
257
+ // removes and returns any item that passes testFunction .
253
258
254
259
getAndRemove.byType(
255
260
type: 'object' | 'array' | 'number' | 'string' | 'boolean' | 'function' | 'undefined'
256
261
): IValueIndexPair[]
262
+ // removes and returns any item that is passed type.
257
263
```
258
264
</details >
259
265
260
266
261
267
#### insert: PublicArrayInserter (read-only)
262
- ###### Has methods that increase the length of the array and return the PublicArrayInserter instance:
268
+ ###### Has methods that increase the length of this.data and return the PublicArrayInserter instance:
263
269
<details >
264
270
<summary >view methods</summary >
265
271
@@ -268,16 +274,16 @@ insert.at(index, values: any[]): PublicArrayInserter
268
274
// inserts values at index. index can be negative or positive.
269
275
270
276
insert.middle(values: any[], offset = 0): PublicArrayInserter
271
- // inserts values in middle of the array .
272
- // By default, if the array has odd number of items, values will be inserted just before the
277
+ // inserts values in middle of this.data .
278
+ // By default, if this.data has odd number of items, values will be inserted just before the
273
279
// middle item. If you want to change the insert position, set the optional offset parameter
274
280
// to + or - whatever integer you want.
275
281
```
276
282
</details >
277
283
278
284
279
285
#### remove: PublicArrayRemover (read-only)
280
- ###### Has methods that all remove items from the array and return the PublicArrayRemover instance:
286
+ ###### Has methods that all remove items from this.data and return the PublicArrayRemover instance:
281
287
<details >
282
288
<summary >view methods</summary >
283
289
@@ -294,7 +300,7 @@ remove.adjacentAt(startingIndex, numItemsToRemove): PublicArrayRemover
294
300
remove.adjacentToValue(info: IAdjacentToValueInfo): PublicArrayRemover
295
301
/************
296
302
Removes adjacent items including, or near, a particular value.
297
- Only applies to the first instance of value found in array .
303
+ Only applies to the first instance of value found in this.data .
298
304
The parameter 'info' is an object that looks like this:
299
305
{
300
306
value: any except object (the value to search for in the array),
@@ -304,15 +310,15 @@ remove.adjacentToValue(info: IAdjacentToValueInfo): PublicArrayRemover
304
310
}
305
311
Example:
306
312
// arr.data is [1,2,3,4,5,6,7,8,9,10]
307
- arr.remove.adjacentToValue({value:5, offset: -2 , howMany:3 });
308
- // arr.data is now [1,2,6,7 ,8,9,10]
313
+ arr.remove.adjacentToValue({value:5, offset: 1 , howMany:2 });
314
+ // arr.data is now [1,2,3,4,5 ,8,9,10]
309
315
*************/
310
316
311
317
remove.head(numItemsToRemove): PublicArrayRemover
312
- // Removes numItemsToRemove from array's beginning.
318
+ // Removes numItemsToRemove from beginning of this.data .
313
319
314
320
remove.tail(numItemsToRemove): PublicArrayRemover
315
- // Removes numItemsToRemove from array's end.
321
+ // Removes numItemsToRemove from end of this.data .
316
322
317
323
remove.between(numItemsToKeepAtEachEnd): PublicArrayRemover
318
324
// Removes everything between numItemsToKeepAtEachEnd.
@@ -361,7 +367,7 @@ remove.byType(
361
367
362
368
363
369
#### replace: PublicArrayReplacer (read-only)
364
- ###### Has methods that all replace items in the array and return the PublicArrayReplacer instance:
370
+ ###### Its methods all replace items in this.data and return the PublicArrayReplacer instance:
365
371
<details >
366
372
<summary >view methods</summary >
367
373
@@ -377,7 +383,7 @@ replace.adjacentAt(startingIndex, newValues: any[]): PublicArrayReplacer
377
383
replace.adjacentToValue(info: IAdjacentToValueInfo, newValues: any[]): PublicArrayReplacer
378
384
/**********
379
385
Replaces adjacent items including, or near a particular value, with newValues.
380
- Only applies to the first instance of value found in array .
386
+ Only applies to the first instance of value found in this.data .
381
387
The parameter 'info' is an object that looks like this:
382
388
{
383
389
value: any except object (the value to search for in the array),
@@ -386,10 +392,10 @@ replace.adjacentToValue(info: IAdjacentToValueInfo, newValues: any[]): PublicArr
386
392
howMany: integer greater than zero (it's how many adjacent items to replace)
387
393
}
388
394
Example:
389
- // array is [1,2,3,4,5,6,7,8] .
395
+ // this.data is [1,2,3,4,5,6,7,8]
390
396
// let newValues = [20,30,40];
391
397
// this.adjacentToValue({value: 5, offset: -1, howMany: 2}, newValues);
392
- // array is now [1,2,3,20,30,40,6,7,8]
398
+ // this.data is now [1,2,3,20,30,40,6,7,8]
393
399
**********/
394
400
395
401
replace.between(numItemsToKeepAtEachEnd, newValues: any[]): PublicArrayReplacer
@@ -407,19 +413,19 @@ replace.firstOf(value, newValue): PublicArrayReplacer
407
413
// Replaces first instance of value with newValue.
408
414
409
415
replace.firstOfEach(values: any[], newValues: any[]): PublicArrayReplacer
410
- // First instance of values[i] found in array gets replaced with newValues[i].
416
+ // First instance of values[i] found in this.data gets replaced with newValues[i].
411
417
412
418
replace.allOf(value, newValue): PublicArrayReplacer
413
419
// Replaces all instances of value with newValue.
414
420
415
421
replace.allOfEach(values: any[], newValues: any[]): PublicArrayReplacer
416
- // All instances of values[i] found in array get replaced with newValues[i].
422
+ // All instances of values[i] found in this.data get replaced with newValues[i].
417
423
418
424
replace.each(replacementFunction: (currentValue, currentIndex?, array?) => any): PublicArrayReplacer
419
425
/**********
420
- Loops thru array , passing each item into replacementFunction.
421
- replacementFunction must return the new value you want to give to that index in the array .
422
- If you don't want to give a particular index a new value, simply return the value it already
426
+ Loops thru this.data , passing each item into replacementFunction.
427
+ replacementFunction must return the new value you want to give to that item in this.data .
428
+ If you don't want to give a particular item a new value, simply return the value it already
423
429
has.
424
430
Important to remember: even if the currentValue should not be replaced, you still must return
425
431
something, or else that item will become undefined.
@@ -440,19 +446,19 @@ replace.allWithOne(values: any[], newValue): PublicArrayReplacer
440
446
441
447
442
448
#### sort: PublicArraySorter (read-only)
443
- ###### Has methods that change the order of the items and return the PublicArraySorter instance:
449
+ ###### Its methods change the order of items in this.data and return the PublicArraySorter instance:
444
450
<details >
445
451
<summary >view methods</summary >
446
452
447
453
```
448
454
sort.alphabetize(): PublicArraySorter;
449
- // No item in the array gets modified, but each is treated as a string during the sorting.
455
+ // No item in this.data gets modified, but each is treated as a string during the sorting.
450
456
451
457
sort.numbersAscending(): PublicArraySorter;
452
- // If not all items in array are of type 'number', it triggers error.
458
+ // If not all items in this.data are of type 'number', it triggers error.
453
459
454
460
sort.numbersDescending(): PublicArraySorter;
455
- // If not all items in array are of type 'number', it triggers error.
461
+ // If not all items in this.data are of type 'number', it triggers error.
456
462
457
463
sort.reverse(): PublicArraySorter;
458
464
@@ -480,27 +486,27 @@ asString(glue = ', '): string
480
486
************/
481
487
482
488
has(value): boolean
483
- // returns true if array contains value.
489
+ // returns true if this.data contains value.
484
490
485
491
hasAll(values: any[]): boolean
486
- // returns true if array contains every value in values.
492
+ // returns true if this.data contains every value in values.
487
493
488
494
hasAny(values: any[]): boolean
489
- // returns true if array contains at least 1 value in values.
495
+ // returns true if this.data contains at least 1 value in values.
490
496
491
497
hasAdjacent(values: any[]): boolean
492
- // returns true if array contains exact sequence of values.
498
+ // returns true if this.data contains exact sequence of values.
493
499
// Example: if this.data is [10,1,2,3,11], then this.hasAdjacent([1,2,3]) returns true.
494
500
495
501
startsWith(values: any[]): boolean
496
- // returns true if array starts with exact sequence of values.
502
+ // returns true if this.data starts with exact sequence of values.
497
503
498
504
endsWith(values: any[]): boolean
499
- // returns true if array ends with exact sequence of values.
505
+ // returns true if this.data ends with exact sequence of values.
500
506
501
507
matches(array): boolean
502
- // returns true if entire array matches passed array exactly.
503
- // returns false if passed array contains object.
508
+ // returns true if this.data matches passed array exactly.
509
+ // will return false if this.data or passed array contains object.
504
510
505
511
// For the next 3 methods:
506
512
// testFunction is a callback with same signature as callback passed to
@@ -509,28 +515,28 @@ matches(array): boolean
509
515
// checks if currentValue passes test. If yes, it returns true.
510
516
511
517
allPass(testFunction): boolean
512
- // returns true if all items pass test.
518
+ // returns true if all items in this.data pass test.
513
519
514
520
anyPass(testFunction): boolean
515
- // returns true if at least 1 item passes.
521
+ // returns true if at least 1 item passes test .
516
522
517
523
indexesThatPass(testFunction): number[]
518
- // returns all indexes of items that pass test. If none pass, returns empty array.
524
+ // returns indexes of all items that pass test. If none pass, returns empty array.
519
525
520
526
firstIndexOf(value): number
521
- // returns index of first instance of value in array . If not found, returns -1.
527
+ // returns index of first instance of value in this.data . If not found, returns -1.
522
528
523
529
lastIndexOf(value): number
524
- // returns index of last instance of value in array . If not found, returns -1.
530
+ // returns index of last instance of value in this.data . If not found, returns -1.
525
531
526
532
indexesOf(value): number[]
527
- // returns all indexes of value in array . If not found, returns empty array.
533
+ // returns all indexes of value in this.data . If not found, returns empty array.
528
534
529
535
append(values: any[]): this
530
- // attaches values to end of array .
536
+ // attaches values to end of this.data .
531
537
532
538
prepend(values: any[]): this
533
- // attaches values to beginning of array .
539
+ // attaches values to beginning of this.data .
534
540
535
541
forEach(iterationFunction): this
536
542
// Behaves same as Array.forEach()
0 commit comments