Skip to content

Commit 328d5ce

Browse files
author
Steve Thompson
committed
more improvements to README
1 parent 458f1de commit 328d5ce

File tree

1 file changed

+83
-46
lines changed

1 file changed

+83
-46
lines changed

README.md

Lines changed: 83 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ getPublicArray(array = []): PublicArray
4444
// let arr = getPublicArray([1,2,3,4,5]);
4545
// Or, instantiate with an empty array:
4646
// let arr = getPublicArray();
47-
4847
```
4948

5049
### Properties
@@ -94,10 +93,10 @@ get.copy(): any[]
9493
// Returns independent copy of the array.
9594
9695
get.byIndex(index): any
97-
// Returns 1 item. index can be negative or positive.
96+
// Returns item identified by passed index. index can be negative or positive.
9897
9998
get.byIndexes(indexes): any[]
100-
// indexes can be negative or positive.
99+
// Returns items identified by passed indexes. indexes can be negative or positive.
101100
102101
get.head(numItems): any[]
103102
// returns numItems from beginning
@@ -108,7 +107,7 @@ get.tail(numItems): any[]
108107
get.between(numItemsToIgnoreAtEachEnd): any[]
109108
// Returns middle of array, between numItemsToIgnoreAtEachEnd
110109
111-
get.adjacentAt(startingIndex, numItems): any[]
110+
get.adjacentAt(startingIndex, numItemsToGet): any[]
112111
// Returns adjacent items. startingIndex can be negative or positive.
113112
114113
get.adjacentToValue(info: IAdjacentToValueInfo): any[]
@@ -123,22 +122,24 @@ get.adjacentToValue(info: IAdjacentToValueInfo): any[]
123122
howMany: integer greater than zero (it's how many adjacent items to return)
124123
}
125124
Example:
126-
// arr.data is [1,2,3,4,5,6,7,8,9,10]
127-
let numbers = arr.get.adjacentToValue({value:5, offset: -2, howMany:3});
125+
// this.data is [1,2,3,4,5,6,7,8,9,10]
126+
let numbers = this.get.adjacentToValue({value:5, offset: -2, howMany:3});
128127
// numbers is now [3,4,5]
129128
***************/
130129
130+
// For all the functions below, the parameter 'value' cannot be object.
131+
131132
get.allAfterFirst(value): any[]
132-
// value cannot be object
133+
// returns all items after the first instance of value.
133134
134135
get.allBeforeFirst(value): any[]
135-
// value cannot be object
136+
// returns all items before the first instance of value.
136137
137138
get.allAfterLast(value): any[]
138-
// value cannot be object
139+
// returns all items after the last instance of value.
139140
140141
get.allBeforeLast(value): any[]
141-
// value cannot be object
142+
// returns all items before the last instance of value.
142143
143144
get.uniqueItems(): any[]
144145
// returns no duplicates.
@@ -147,7 +148,7 @@ get.duplicates(): any[]
147148
// returns every instance of a duplicate, so you may get multiple instances.
148149
149150
get.shuffled(): any[]
150-
// returns new, shuffled version of the array
151+
// returns new version of the array with the order of items randomized.
151152
152153
get.byTest(testFunction: ((currentValue, currentIndex?, array?) => boolean)): IValueIndexPair[]
153154
/***************
@@ -159,27 +160,29 @@ get.byTest(testFunction: ((currentValue, currentIndex?, array?) => boolean)): IV
159160
get.byType(
160161
type: 'object' | 'array' | 'number' | 'string' | 'boolean' | 'function' | 'undefined'
161162
): IValueIndexPair[]
162-
// For explanation of IValueIndexPair, see explanation of byTest().
163+
// For explanation of IValueIndexPair, see explanation of get.byTest().
163164
```
164165

165166
#### getAndRemove: PublicArrayGetterRemover (read-only)
166167
###### Has methods that both remove and return items from the array:
167168
```
168169
getAndRemove.byIndex(index): any
169-
// index can be negative or positive.
170+
// removes and returns item identified by passed index. index can be negative or positive.
170171
171172
getAndRemove.byIndexes(indexes): any[]
172-
// indexes can be negative or positive.
173+
// removes and returns items identified by passed indexes. indexes can be negative or positive.
173174
174175
getAndRemove.head(numItemsToRemove): any[]
176+
// removes and returns numItemsToRemove from beginning
175177
176178
getAndRemove.tail(numItemsToRemove): any[]
179+
// removes and returns numItemsToRemove from end
177180
178181
getAndRemove.between(numItemsToKeepAtEachEnd): any[]
179-
// Returns middle of array, between numItemsToIgnoreAtEachEnd
182+
// removes and returns middle of array, between numItemsToKeepAtEachEnd
180183
181184
getAndRemove.adjacentAt(startingIndex, numItemsToRemove): any[]
182-
// startingIndex can be negative or positive.
185+
// removes and returns adjacent items. startingIndex can be negative or positive.
183186
184187
getAndRemove.adjacentToValue(info: IAdjacentToValueInfo): any[]
185188
/********
@@ -193,38 +196,39 @@ getAndRemove.adjacentToValue(info: IAdjacentToValueInfo): any[]
193196
howMany: integer greater than zero (it's how many adjacent items to remove/return)
194197
}
195198
Example:
196-
// arr.data is [1,2,3,4,5,6,7,8,9,10]
197-
let numbers = arr.getAndRemove.adjacentToValue({value:5, offset: -2, howMany:3});
198-
// numbers is now [3,4,5]. getAndRemove.data is now [1,2,6,7,8,9,10]
199+
// this.data is [1,2,3,4,5,6,7,8,9,10]
200+
let numbers = this.getAndRemove.adjacentToValue({value:5, offset: -2, howMany:3});
201+
// numbers is now [3,4,5]. this.data is now [1,2,6,7,8,9,10]
199202
*********/
200203
201204
// For all the functions below, the parameter 'value' cannot be object.
202205
203206
getAndRemove.allAfterFirst(value): any[]
204-
// Removes and returns everything after first instance of value
207+
// removes and returns all items after first instance of value
205208
206209
getAndRemove.allBeforeFirst(value): any[]
207-
// Removes and returns everything before first instance of value
210+
// removes and returns all items before first instance of value
208211
209212
getAndRemove.allAfterLast(value): any[]
210-
// Removes and returns everything after last instance of value
213+
// removes and returns all items after last instance of value
211214
212215
getAndRemove.allBeforeLast(value): any[]
213-
// Removes and returns everything before last instance of value
216+
// removes and returns all items before last instance of value
214217
215218
getAndRemove.duplicates(): any[]
216219
// removes and returns every instance of a duplicate, so you may receive multiple instances.
217220
218221
/************
219222
These last 2 methods both return an array of IValueIndexPairs. A IValueIndexPair looks like this:
220-
221223
{value: any, index: number}
222224
223225
Each one represents a removed array item.
224226
************/
225227
226-
getAndRemove.byTest(testFunction: (currentValue, currentIndex?, array?) => boolean): IValueIndexPair[]
227-
// Gets and removes any value that passes test.
228+
getAndRemove.byTest(
229+
testFunction: (currentValue, currentIndex?, array?) => boolean
230+
): IValueIndexPair[]
231+
// removes and returns any value that passes test.
228232
229233
getAndRemove.byType(
230234
type: 'object' | 'array' | 'number' | 'string' | 'boolean' | 'function' | 'undefined'
@@ -241,8 +245,8 @@ insert.at(index, values: any[]): PublicArrayInserter
241245
insert.middle(values: any[], offset = 0): PublicArrayInserter
242246
// inserts values in middle of the array.
243247
// By default, if the array has odd number of items, values will be inserted just before the
244-
// middle item. If you want to change the insert position, set the optional offset parameter to +
245-
// or - whatever integer you want.
248+
// middle item. If you want to change the insert position, set the optional offset parameter
249+
// to + or - whatever integer you want.
246250
```
247251

248252
#### remove: PublicArrayRemover (read-only)
@@ -316,8 +320,8 @@ remove.allBeforeLast(value): PublicArrayRemover
316320
317321
remove.duplicates(): PublicArrayRemover
318322
319-
remove.byTest(testFunction: (currentItem, currentIndex?, array?) => boolean): PublicArrayRemover
320-
// if currentItem passes test, it is removed.
323+
remove.byTest(testFunction: (currentValue, currentIndex?, array?) => boolean): PublicArrayRemover
324+
// if currentValue passes test, it is removed.
321325
322326
remove.byType(
323327
type: 'object' | 'array' | 'number' | 'string' | 'boolean' | 'function' | 'undefined'
@@ -358,6 +362,12 @@ replace.between(numItemsToKeepAtEachEnd, newValues: any[]): PublicArrayReplacer
358362
// Example: if this.data is [1,2,3,4,5,6,7] , and you call .between(2, [9,10])
359363
// this.data will be [1,2,9,10,6,7] . It preserves the first 2 items and the last 2.
360364
365+
/************
366+
For all the functions below:
367+
Any parameter called 'value' cannot be an object.
368+
Any parameter called 'values' cannot contain an object.
369+
************/
370+
361371
replace.firstOf(value, newValue): PublicArrayReplacer
362372
// Replaces first instance of value with newValue.
363373
@@ -370,14 +380,13 @@ replace.allOf(value, newValue): PublicArrayReplacer
370380
replace.allOfEach(values: any[], newValues: any[]): PublicArrayReplacer
371381
// All instances of values[i] found in array get replaced with newValues[i].
372382
373-
replace.each(replacementFunction: (item, index?, array?) => any): PublicArrayReplacer
383+
replace.each(replacementFunction: (currentValue, currentIndex?, array?) => any): PublicArrayReplacer
374384
/**********
375385
Loops thru array, passing each item into replacementFunction.
376-
replacementFunction signature: function(item, index?, array?): any
377386
replacementFunction must return the new value you want to give to that index in the array.
378387
Example:
379388
// this.data is [1,2,3,4,5,6] .
380-
// this.each((item) => {
389+
// this.replace.each((item) => {
381390
// if (item === 2 || item === 6) return item * 3;
382391
// else return item;
383392
// });
@@ -390,6 +399,22 @@ replace.allWithOne(values: any[], newValue): PublicArrayReplacer
390399
```
391400

392401
#### sort: PublicArraySorter (read-only)
402+
###### Has methods that change the order of the items and return the PublicArraySorter instance:
403+
```
404+
sort.alphabetize(): PublicArraySorter;
405+
// No item in the array gets modified, but each is treated as a string during the sorting.
406+
407+
sort.numbersAscending(): PublicArraySorter;
408+
// If not all items in array are of type 'number', it triggers error.
409+
410+
sort.numbersDescending(): PublicArraySorter;
411+
// If not all items in array are of type 'number', it triggers error.
412+
413+
sort.reverse(): PublicArraySorter;
414+
415+
sort.shuffle(): PublicArraySorter;
416+
// randomizes the order of items.
417+
```
393418

394419
#### className: string (read-only)
395420

@@ -399,31 +424,41 @@ replace.allWithOne(values: any[], newValue): PublicArrayReplacer
399424
```
400425
asString(glue = ', '): string
401426
// Does same thing as Array.join()
427+
428+
/************
429+
For all the functions below:
430+
Any parameter called 'value' cannot be an object.
431+
Any parameter called 'values' cannot contain an object.
432+
************/
402433
403434
has(value): boolean
404-
// returns false if value is object.
435+
// returns true if array contains value.
405436
406437
hasAll(values: any[]): boolean
407-
// returns false if values contains object.
438+
// returns true if array contains every value in values.
408439
409440
hasAny(values: any[]): boolean
441+
// returns true if array contains at least 1 value in values.
410442
411443
hasAdjacent(values: any[]): boolean
412-
// returns false if values contains object.
444+
// returns true if array contains exact sequence of values.
445+
// Example: if this.data is [10,1,2,3,11], then this.hasAdjacent([1,2,3]) returns true.
413446
414447
startsWith(values: any[]): boolean
415-
// returns false if values contains object.
448+
// returns true if array starts with exact sequence of values.
416449
417450
endsWith(values: any[]): boolean
418-
// returns false if values contains object.
451+
// returns true if array ends with exact sequence of values.
419452
420453
matches(array): boolean
421-
// returns false if array contains object.
454+
// returns true if entire array matches passed array exactly.
455+
// returns false if passed array contains object.
422456
423457
// For the next 3 methods:
424458
// testFunction is a callback with same signature as callback passed to
425459
// Array.filter() :
426-
// testFunction(value, index?, theArray?): checks if value passes test. If yes, it returns true.
460+
// testFunction(currentValue, currentIndex?, entireArray?): boolean
461+
// checks if currentValue passes test. If yes, it returns true.
427462
428463
allPass(testFunction): boolean
429464
// returns true if all items pass test.
@@ -435,20 +470,23 @@ indexesThatPass(testFunction): number[]
435470
// returns all indexes of items that pass test.
436471
437472
firstIndexOf(value): number
438-
// Does not work if value is object.
473+
// returns index of first instance of value in array. If not found, returns -1.
439474
440475
lastIndexOf(value): number
441-
// Does not work if value is object.
476+
// returns index of last instance of value in array. If not found, returns -1.
442477
443478
indexesOf(value): number[]
444-
// Does not work if value is object.
479+
// returns all indexes of value in array. If not found, returns empty array.
445480
446481
append(values: any[]): this
482+
// attaches values to end of array.
447483
448484
prepend(values: any[]): this
485+
// attaches values to beginning of array.
449486
450487
forEach(iterationFunction): this
451-
// iterationFunction = function(currentItem, currentIndex?, entireArray?){...}
488+
// Behaves same as Array.forEach()
489+
// iterationFunction = function(currentValue, currentIndex?, entireArray?){...}
452490
453491
protected _createGetterAndOrSetterForEach(
454492
propertyNames: string[],
@@ -469,12 +507,11 @@ runMethod_and_returnThis(
469507

470508

471509

472-
## Usage
510+
## Usage Examples
473511

474512
```
475513
// changing the array content:
476514
arr.data = [1,2,3,4,5,6,7];
477-
478515
```
479516

480517
## Performance

0 commit comments

Comments
 (0)