@@ -66,9 +66,8 @@ getPublicArray(array = []): PublicArray
66
66
#### filter: PublicArrayFilter (read-only)
67
67
###### Has methods that narrow down the content of the array and return the PublicArrayFilter instance:
68
68
```
69
- filter.byTest(testFunction): PublicArrayFilter
69
+ filter.byTest(testFunction: ((currentValue, currentIndex?, array?) => boolean) ): PublicArrayFilter
70
70
// Narrows down the array to only the values that pass testFunction.
71
- // testFunction = function(currentValue, currentIndex?, theArray?): boolean
72
71
73
72
filter.byType(
74
73
type: 'number' | 'boolean' | 'string' | 'array' | 'object' | 'function' | 'undefined'
@@ -129,16 +128,16 @@ get.adjacentToValue(info: IAdjacentToValueInfo): any[]
129
128
// numbers is now [3,4,5]
130
129
***************/
131
130
132
- get.allAfterFirst(value: any ): any[]
131
+ get.allAfterFirst(value): any[]
133
132
// value cannot be object
134
133
135
- get.allBeforeFirst(value: any ): any[]
134
+ get.allBeforeFirst(value): any[]
136
135
// value cannot be object
137
136
138
- get.allAfterLast(value: any ): any[]
137
+ get.allAfterLast(value): any[]
139
138
// value cannot be object
140
139
141
- get.allBeforeLast(value: any ): any[]
140
+ get.allBeforeLast(value): any[]
142
141
// value cannot be object
143
142
144
143
get.uniqueItems(): any[]
@@ -182,7 +181,7 @@ getAndRemove.between(numItemsToKeepAtEachEnd): any[]
182
181
getAndRemove.adjacentAt(startingIndex, numItemsToRemove): any[]
183
182
// startingIndex can be negative or positive.
184
183
185
- getAndRemove.adjacentToValue(info): any[]
184
+ getAndRemove.adjacentToValue(info: IAdjacentToValueInfo ): any[]
186
185
/********
187
186
Removes and returns adjacent items including, or near, a particular value.
188
187
Only applies to the first instance of value found in array.
@@ -201,16 +200,16 @@ getAndRemove.adjacentToValue(info): any[]
201
200
202
201
// For all the functions below, the parameter 'value' cannot be object.
203
202
204
- getAndRemove.allAfterFirst(value: any ): any[]
203
+ getAndRemove.allAfterFirst(value): any[]
205
204
// Removes and returns everything after first instance of value
206
205
207
- getAndRemove.allBeforeFirst(value: any ): any[]
206
+ getAndRemove.allBeforeFirst(value): any[]
208
207
// Removes and returns everything before first instance of value
209
208
210
- getAndRemove.allAfterLast(value: any ): any[]
209
+ getAndRemove.allAfterLast(value): any[]
211
210
// Removes and returns everything after last instance of value
212
211
213
- getAndRemove.allBeforeLast(value: any ): any[]
212
+ getAndRemove.allBeforeLast(value): any[]
214
213
// Removes and returns everything before last instance of value
215
214
216
215
getAndRemove.duplicates(): any[]
@@ -249,16 +248,16 @@ insert.middle(values: any[], offset = 0): PublicArrayInserter
249
248
#### remove: PublicArrayRemover (read-only)
250
249
###### Has methods that all remove items from the array and return the PublicArrayRemover instance:
251
250
```
252
- remove.byIndex(index): this
251
+ remove.byIndex(index): PublicArrayRemover
253
252
// index can be negative or positive.
254
253
255
- remove.byIndexes(indexes): this
254
+ remove.byIndexes(indexes): PublicArrayRemover
256
255
// indexes can be negative or positive.
257
256
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.
260
259
261
- remove.adjacentToValue(info): this
260
+ remove.adjacentToValue(info: IAdjacentToValueInfo ): PublicArrayRemover
262
261
/************
263
262
Removes adjacent items including, or near, a particular value.
264
263
Only applies to the first instance of value found in array.
@@ -275,53 +274,120 @@ remove.adjacentToValue(info): this
275
274
// arr.data is now [1,2,6,7,8,9,10]
276
275
*************/
277
276
278
- remove.head(numItemsToRemove): this
277
+ remove.head(numItemsToRemove): PublicArrayRemover
279
278
// Removes numItemsToRemove from array's beginning.
280
279
281
- remove.tail(numItemsToRemove): this
280
+ remove.tail(numItemsToRemove): PublicArrayRemover
282
281
// Removes numItemsToRemove from array's end.
283
282
284
- remove.between(numItemsToKeepAtEachEnd): this
283
+ remove.between(numItemsToKeepAtEachEnd): PublicArrayRemover
285
284
// Removes everything between numItemsToKeepAtEachEnd.
286
285
// 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
+ ************/
287
292
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.
291
295
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.
295
298
296
- remove.allOf(value): this
299
+ remove.allOf(value): PublicArrayRemover
297
300
// Removes all instances of value.
298
301
299
- remove.allOfEach(values: any[]): this
302
+ remove.allOfEach(values: any[]): PublicArrayRemover
300
303
// Removes all instances of each value.
301
304
302
- remove.allAfterFirst(value: any ): this
305
+ remove.allAfterFirst(value): PublicArrayRemover
303
306
// Removes all items after first instance of value.
304
307
305
- remove.allBeforeFirst(value: any ): this
308
+ remove.allBeforeFirst(value): PublicArrayRemover
306
309
// Removes all items before first instance of value.
307
310
308
- remove.allAfterLast(value): this
311
+ remove.allAfterLast(value): PublicArrayRemover
309
312
// Removes all items after last instance of value.
310
313
311
- remove.allBeforeLast(value): this
314
+ remove.allBeforeLast(value): PublicArrayRemover
312
315
// Removes all items before last instance of value.
313
316
314
- remove.duplicates(): this
317
+ remove.duplicates(): PublicArrayRemover
315
318
316
- remove.byTest(testFunction: (currentItem, currentIndex?, array?) => boolean): this
319
+ remove.byTest(testFunction: (currentItem, currentIndex?, array?) => boolean): PublicArrayRemover
317
320
// if currentItem passes test, it is removed.
318
321
319
322
remove.byType(
320
323
type: 'object' | 'array' | 'number' | 'string' | 'boolean' | 'function' | 'undefined'
321
- ): this
324
+ ): PublicArrayRemover
322
325
```
323
326
324
327
#### 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
+ ```
325
391
326
392
#### sort: PublicArraySorter (read-only)
327
393
0 commit comments