Skip to content

Commit 458f1de

Browse files
author
Steve Thompson
committed
Added documentation to README that covers the methods attached to replace property
1 parent dd01c9d commit 458f1de

File tree

1 file changed

+100
-34
lines changed

1 file changed

+100
-34
lines changed

README.md

Lines changed: 100 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ getPublicArray(array = []): PublicArray
6666
#### filter: PublicArrayFilter (read-only)
6767
###### Has methods that narrow down the content of the array and return the PublicArrayFilter instance:
6868
```
69-
filter.byTest(testFunction): PublicArrayFilter
69+
filter.byTest(testFunction: ((currentValue, currentIndex?, array?) => boolean)): PublicArrayFilter
7070
// Narrows down the array to only the values that pass testFunction.
71-
// testFunction = function(currentValue, currentIndex?, theArray?): boolean
7271
7372
filter.byType(
7473
type: 'number' | 'boolean' | 'string' | 'array' | 'object' | 'function' | 'undefined'
@@ -129,16 +128,16 @@ get.adjacentToValue(info: IAdjacentToValueInfo): any[]
129128
// numbers is now [3,4,5]
130129
***************/
131130
132-
get.allAfterFirst(value: any): any[]
131+
get.allAfterFirst(value): any[]
133132
// value cannot be object
134133
135-
get.allBeforeFirst(value: any): any[]
134+
get.allBeforeFirst(value): any[]
136135
// value cannot be object
137136
138-
get.allAfterLast(value: any): any[]
137+
get.allAfterLast(value): any[]
139138
// value cannot be object
140139
141-
get.allBeforeLast(value: any): any[]
140+
get.allBeforeLast(value): any[]
142141
// value cannot be object
143142
144143
get.uniqueItems(): any[]
@@ -182,7 +181,7 @@ getAndRemove.between(numItemsToKeepAtEachEnd): any[]
182181
getAndRemove.adjacentAt(startingIndex, numItemsToRemove): any[]
183182
// startingIndex can be negative or positive.
184183
185-
getAndRemove.adjacentToValue(info): any[]
184+
getAndRemove.adjacentToValue(info: IAdjacentToValueInfo): any[]
186185
/********
187186
Removes and returns adjacent items including, or near, a particular value.
188187
Only applies to the first instance of value found in array.
@@ -201,16 +200,16 @@ getAndRemove.adjacentToValue(info): any[]
201200
202201
// For all the functions below, the parameter 'value' cannot be object.
203202
204-
getAndRemove.allAfterFirst(value: any): any[]
203+
getAndRemove.allAfterFirst(value): any[]
205204
// Removes and returns everything after first instance of value
206205
207-
getAndRemove.allBeforeFirst(value: any): any[]
206+
getAndRemove.allBeforeFirst(value): any[]
208207
// Removes and returns everything before first instance of value
209208
210-
getAndRemove.allAfterLast(value: any): any[]
209+
getAndRemove.allAfterLast(value): any[]
211210
// Removes and returns everything after last instance of value
212211
213-
getAndRemove.allBeforeLast(value: any): any[]
212+
getAndRemove.allBeforeLast(value): any[]
214213
// Removes and returns everything before last instance of value
215214
216215
getAndRemove.duplicates(): any[]
@@ -249,16 +248,16 @@ insert.middle(values: any[], offset = 0): PublicArrayInserter
249248
#### remove: PublicArrayRemover (read-only)
250249
###### Has methods that all remove items from the array and return the PublicArrayRemover instance:
251250
```
252-
remove.byIndex(index): this
251+
remove.byIndex(index): PublicArrayRemover
253252
// index can be negative or positive.
254253
255-
remove.byIndexes(indexes): this
254+
remove.byIndexes(indexes): PublicArrayRemover
256255
// indexes can be negative or positive.
257256
258-
remove.adjacentAt(startingIndex, numItemsToRemove): this
259-
// startingIndex can be negative or positive. Removes adjacent items.
257+
remove.adjacentAt(startingIndex, numItemsToRemove): PublicArrayRemover
258+
// Removes adjacent items. startingIndex can be negative or positive.
260259
261-
remove.adjacentToValue(info): this
260+
remove.adjacentToValue(info: IAdjacentToValueInfo): PublicArrayRemover
262261
/************
263262
Removes adjacent items including, or near, a particular value.
264263
Only applies to the first instance of value found in array.
@@ -275,53 +274,120 @@ remove.adjacentToValue(info): this
275274
// arr.data is now [1,2,6,7,8,9,10]
276275
*************/
277276
278-
remove.head(numItemsToRemove): this
277+
remove.head(numItemsToRemove): PublicArrayRemover
279278
// Removes numItemsToRemove from array's beginning.
280279
281-
remove.tail(numItemsToRemove): this
280+
remove.tail(numItemsToRemove): PublicArrayRemover
282281
// Removes numItemsToRemove from array's end.
283282
284-
remove.between(numItemsToKeepAtEachEnd): this
283+
remove.between(numItemsToKeepAtEachEnd): PublicArrayRemover
285284
// Removes everything between numItemsToKeepAtEachEnd.
286285
// i.e., if numItemsToKeepAtEachEnd = 2, then only the first 2 items and last 2 items will remain.
286+
287+
/************
288+
For all the functions below:
289+
Any parameter called 'value' cannot be an object.
290+
Any parameter called 'values' cannot contain an object.
291+
************/
287292
288-
remove.firstOf(value): this
289-
// Removes first instance of value. value cannot be object (that applies to all functions here
290-
// with a parameter called 'value').
293+
remove.firstOf(value): PublicArrayRemover
294+
// Removes first instance of value.
291295
292-
remove.firstOfEach(values: any[]): this
293-
// Removes first instance of each value. values cannot contain object (that applies to all functions
294-
// here with a parameter called 'values').
296+
remove.firstOfEach(values: any[]): PublicArrayRemover
297+
// Removes first instance of each value.
295298
296-
remove.allOf(value): this
299+
remove.allOf(value): PublicArrayRemover
297300
// Removes all instances of value.
298301
299-
remove.allOfEach(values: any[]): this
302+
remove.allOfEach(values: any[]): PublicArrayRemover
300303
// Removes all instances of each value.
301304
302-
remove.allAfterFirst(value: any): this
305+
remove.allAfterFirst(value): PublicArrayRemover
303306
// Removes all items after first instance of value.
304307
305-
remove.allBeforeFirst(value: any): this
308+
remove.allBeforeFirst(value): PublicArrayRemover
306309
// Removes all items before first instance of value.
307310
308-
remove.allAfterLast(value): this
311+
remove.allAfterLast(value): PublicArrayRemover
309312
// Removes all items after last instance of value.
310313
311-
remove.allBeforeLast(value): this
314+
remove.allBeforeLast(value): PublicArrayRemover
312315
// Removes all items before last instance of value.
313316
314-
remove.duplicates(): this
317+
remove.duplicates(): PublicArrayRemover
315318
316-
remove.byTest(testFunction: (currentItem, currentIndex?, array?) => boolean): this
319+
remove.byTest(testFunction: (currentItem, currentIndex?, array?) => boolean): PublicArrayRemover
317320
// if currentItem passes test, it is removed.
318321
319322
remove.byType(
320323
type: 'object' | 'array' | 'number' | 'string' | 'boolean' | 'function' | 'undefined'
321-
): this
324+
): PublicArrayRemover
322325
```
323326

324327
#### replace: PublicArrayReplacer (read-only)
328+
###### Has methods that all replace items in the array and return the PublicArrayReplacer instance:
329+
```
330+
replace.at(index, newValue): PublicArrayReplacer
331+
// Replaces item at index with newValue. index can be negative or positive.
332+
333+
replace.adjacentAt(startingIndex, newValues: any[]): PublicArrayReplacer
334+
// Replaces adjacent items beginning at startingIndex with newValues.
335+
// Number of adjacent items that are replaced is same as number of items in newValues.
336+
// startingIndex can be negative or positive.
337+
338+
replace.adjacentToValue(info: IAdjacentToValueInfo, newValues: any[]): PublicArrayReplacer
339+
/**********
340+
Replaces adjacent items including, or near a particular value, with newValues.
341+
Only applies to the first instance of value found in array.
342+
The parameter 'info' is an object that looks like this:
343+
{
344+
value: any except object (the value to search for in the array),
345+
offset: integer (tells function where, in relation to value, to begin selecting adjacent
346+
items to replace. If offset is zero, the selection will begin with value.)
347+
howMany: integer greater than zero (it's how many adjacent items to replace)
348+
}
349+
Example:
350+
// array is [1,2,3,4,5,6,7,8] .
351+
// let newValues = [20,30,40];
352+
// this.adjacentToValue({value: 5, offset: -1, howMany: 2}, newValues);
353+
// array is now [1,2,3,20,30,40,6,7,8]
354+
**********/
355+
356+
replace.between(numItemsToKeepAtEachEnd, newValues: any[]): PublicArrayReplacer
357+
// Replaces everything between numItemsToKeepAtEachEnd with newValues.
358+
// Example: if this.data is [1,2,3,4,5,6,7] , and you call .between(2, [9,10])
359+
// this.data will be [1,2,9,10,6,7] . It preserves the first 2 items and the last 2.
360+
361+
replace.firstOf(value, newValue): PublicArrayReplacer
362+
// Replaces first instance of value with newValue.
363+
364+
replace.firstOfEach(values: any[], newValues: any[]): PublicArrayReplacer
365+
// First instance of values[i] found in array gets replaced with newValues[i].
366+
367+
replace.allOf(value, newValue): PublicArrayReplacer
368+
// Replaces all instances of value with newValue.
369+
370+
replace.allOfEach(values: any[], newValues: any[]): PublicArrayReplacer
371+
// All instances of values[i] found in array get replaced with newValues[i].
372+
373+
replace.each(replacementFunction: (item, index?, array?) => any): PublicArrayReplacer
374+
/**********
375+
Loops thru array, passing each item into replacementFunction.
376+
replacementFunction signature: function(item, index?, array?): any
377+
replacementFunction must return the new value you want to give to that index in the array.
378+
Example:
379+
// this.data is [1,2,3,4,5,6] .
380+
// this.each((item) => {
381+
// if (item === 2 || item === 6) return item * 3;
382+
// else return item;
383+
// });
384+
// this.data is now [1,6,3,4,5,18]
385+
**********/
386+
387+
388+
replace.allWithOne(values: any[], newValue): PublicArrayReplacer
389+
// Replaces all instances of each value in values with newValue.
390+
```
325391

326392
#### sort: PublicArraySorter (read-only)
327393

0 commit comments

Comments
 (0)