Skip to content

Commit c2412b9

Browse files
author
Steve Thompson
committed
more changes to README
1 parent 74e47c0 commit c2412b9

File tree

2 files changed

+66
-61
lines changed

2 files changed

+66
-61
lines changed

README.md

Lines changed: 66 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ getPublicArray(array = []): PublicArray
6565

6666
## Properties with methods
6767

68+
Helpful tidbit: These properties all contain their own `.data` property, which always matches `this.data`
69+
6870
#### filter: PublicArrayFilter (read-only)
6971
###### Its methods narrow down the content of this.data and return the PublicArrayFilter instance:
7072
<details>
@@ -83,7 +85,7 @@ filter.byType(
8385

8486

8587
#### 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 .
8789
<details>
8890
<summary>view methods</summary>
8991

@@ -98,21 +100,21 @@ get.byIndexes(indexes): any[]
98100
// Returns items identified by passed indexes. indexes can be negative or positive.
99101
100102
get.head(numItems): any[]
101-
// returns numItems from beginning
103+
// returns numItems from beginning of this.data
102104
103105
get.tail(numItems): any[]
104-
// returns numItems from end
106+
// returns numItems from end of this.data
105107
106108
get.between(numItemsToIgnoreAtEachEnd): any[]
107-
// Returns middle of array, between numItemsToIgnoreAtEachEnd
109+
// Returns middle of this.data, between numItemsToIgnoreAtEachEnd
108110
109111
get.adjacentAt(startingIndex, numItemsToGet): any[]
110112
// Returns adjacent items. startingIndex can be negative or positive.
111113
112114
get.adjacentToValue(info: IAdjacentToValueInfo): any[]
113115
/**************
114116
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.
116118
The parameter 'info' is an object that looks like this:
117119
{
118120
value: any except object (the value to search for in the array),
@@ -147,42 +149,45 @@ get.duplicates(): any[]
147149
// returns every instance of a duplicate, so you may get multiple instances.
148150
149151
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+
************/
151160
152161
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.
158163
159164
get.byType(
160165
type: 'object' | 'array' | 'number' | 'string' | 'boolean' | 'function' | 'undefined'
161166
): IValueIndexPair[]
162-
// For explanation of IValueIndexPair, see explanation of get.byTest().
167+
// returns any item that is passed type.
163168
```
164169
</details>
165170

166171

167172
#### 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 .
169174
<details>
170175
<summary>view methods</summary>
171176

172177
```
173178
getConverted.toOne(
174179
reducingFunction: ((previousValue: any, currentValue: any, index?, array?) => any)
175180
): 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.
177182
178183
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.
180185
```
181186
</details>
182187

183188

184189
#### 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:
186191
<details>
187192
<summary>view methods</summary>
188193

@@ -200,15 +205,15 @@ getAndRemove.tail(numItemsToRemove): any[]
200205
// removes and returns numItemsToRemove from end
201206
202207
getAndRemove.between(numItemsToKeepAtEachEnd): any[]
203-
// removes and returns middle of array, between numItemsToKeepAtEachEnd
208+
// removes and returns middle of this.data, between numItemsToKeepAtEachEnd
204209
205210
getAndRemove.adjacentAt(startingIndex, numItemsToRemove): any[]
206211
// removes and returns adjacent items. startingIndex can be negative or positive.
207212
208213
getAndRemove.adjacentToValue(info: IAdjacentToValueInfo): any[]
209214
/********
210215
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 .
212217
The parameter 'info' is an object that looks like this:
213218
{
214219
value: any except object (the value to search for in the array),
@@ -218,8 +223,8 @@ getAndRemove.adjacentToValue(info: IAdjacentToValueInfo): any[]
218223
}
219224
Example:
220225
// 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]
223228
*********/
224229
225230
// For all the functions below, the parameter 'value' cannot be object.
@@ -243,23 +248,24 @@ getAndRemove.duplicates(): any[]
243248
These last 2 methods both return an array of IValueIndexPairs. A IValueIndexPair looks like this:
244249
{value: any, index: number}
245250
246-
Each one represents a removed array item.
251+
Each one represents an item removed from this.data .
247252
************/
248253
249254
getAndRemove.byTest(
250255
testFunction: (currentValue, currentIndex?, array?) => boolean
251256
): IValueIndexPair[]
252-
// removes and returns any value that passes test.
257+
// removes and returns any item that passes testFunction.
253258
254259
getAndRemove.byType(
255260
type: 'object' | 'array' | 'number' | 'string' | 'boolean' | 'function' | 'undefined'
256261
): IValueIndexPair[]
262+
// removes and returns any item that is passed type.
257263
```
258264
</details>
259265

260266

261267
#### 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:
263269
<details>
264270
<summary>view methods</summary>
265271

@@ -268,16 +274,16 @@ insert.at(index, values: any[]): PublicArrayInserter
268274
// inserts values at index. index can be negative or positive.
269275
270276
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
273279
// middle item. If you want to change the insert position, set the optional offset parameter
274280
// to + or - whatever integer you want.
275281
```
276282
</details>
277283

278284

279285
#### 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:
281287
<details>
282288
<summary>view methods</summary>
283289

@@ -294,7 +300,7 @@ remove.adjacentAt(startingIndex, numItemsToRemove): PublicArrayRemover
294300
remove.adjacentToValue(info: IAdjacentToValueInfo): PublicArrayRemover
295301
/************
296302
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 .
298304
The parameter 'info' is an object that looks like this:
299305
{
300306
value: any except object (the value to search for in the array),
@@ -304,15 +310,15 @@ remove.adjacentToValue(info: IAdjacentToValueInfo): PublicArrayRemover
304310
}
305311
Example:
306312
// 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]
309315
*************/
310316
311317
remove.head(numItemsToRemove): PublicArrayRemover
312-
// Removes numItemsToRemove from array's beginning.
318+
// Removes numItemsToRemove from beginning of this.data .
313319
314320
remove.tail(numItemsToRemove): PublicArrayRemover
315-
// Removes numItemsToRemove from array's end.
321+
// Removes numItemsToRemove from end of this.data .
316322
317323
remove.between(numItemsToKeepAtEachEnd): PublicArrayRemover
318324
// Removes everything between numItemsToKeepAtEachEnd.
@@ -361,7 +367,7 @@ remove.byType(
361367

362368

363369
#### 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:
365371
<details>
366372
<summary>view methods</summary>
367373

@@ -377,7 +383,7 @@ replace.adjacentAt(startingIndex, newValues: any[]): PublicArrayReplacer
377383
replace.adjacentToValue(info: IAdjacentToValueInfo, newValues: any[]): PublicArrayReplacer
378384
/**********
379385
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 .
381387
The parameter 'info' is an object that looks like this:
382388
{
383389
value: any except object (the value to search for in the array),
@@ -386,10 +392,10 @@ replace.adjacentToValue(info: IAdjacentToValueInfo, newValues: any[]): PublicArr
386392
howMany: integer greater than zero (it's how many adjacent items to replace)
387393
}
388394
Example:
389-
// array is [1,2,3,4,5,6,7,8] .
395+
// this.data is [1,2,3,4,5,6,7,8]
390396
// let newValues = [20,30,40];
391397
// 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]
393399
**********/
394400
395401
replace.between(numItemsToKeepAtEachEnd, newValues: any[]): PublicArrayReplacer
@@ -407,19 +413,19 @@ replace.firstOf(value, newValue): PublicArrayReplacer
407413
// Replaces first instance of value with newValue.
408414
409415
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].
411417
412418
replace.allOf(value, newValue): PublicArrayReplacer
413419
// Replaces all instances of value with newValue.
414420
415421
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].
417423
418424
replace.each(replacementFunction: (currentValue, currentIndex?, array?) => any): PublicArrayReplacer
419425
/**********
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
423429
has.
424430
Important to remember: even if the currentValue should not be replaced, you still must return
425431
something, or else that item will become undefined.
@@ -440,19 +446,19 @@ replace.allWithOne(values: any[], newValue): PublicArrayReplacer
440446

441447

442448
#### 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:
444450
<details>
445451
<summary>view methods</summary>
446452

447453
```
448454
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.
450456
451457
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.
453459
454460
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.
456462
457463
sort.reverse(): PublicArraySorter;
458464
@@ -480,27 +486,27 @@ asString(glue = ', '): string
480486
************/
481487
482488
has(value): boolean
483-
// returns true if array contains value.
489+
// returns true if this.data contains value.
484490
485491
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.
487493
488494
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.
490496
491497
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.
493499
// Example: if this.data is [10,1,2,3,11], then this.hasAdjacent([1,2,3]) returns true.
494500
495501
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.
497503
498504
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.
500506
501507
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.
504510
505511
// For the next 3 methods:
506512
// testFunction is a callback with same signature as callback passed to
@@ -509,28 +515,28 @@ matches(array): boolean
509515
// checks if currentValue passes test. If yes, it returns true.
510516
511517
allPass(testFunction): boolean
512-
// returns true if all items pass test.
518+
// returns true if all items in this.data pass test.
513519
514520
anyPass(testFunction): boolean
515-
// returns true if at least 1 item passes.
521+
// returns true if at least 1 item passes test.
516522
517523
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.
519525
520526
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.
522528
523529
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.
525531
526532
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.
528534
529535
append(values: any[]): this
530-
// attaches values to end of array.
536+
// attaches values to end of this.data.
531537
532538
prepend(values: any[]): this
533-
// attaches values to beginning of array.
539+
// attaches values to beginning of this.data.
534540
535541
forEach(iterationFunction): this
536542
// Behaves same as Array.forEach()

lib/privy/PublicArray.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,3 @@ export class PublicArray extends PublicArrayContent {
107107

108108

109109
}
110-

0 commit comments

Comments
 (0)