Skip to content

Commit dd53a23

Browse files
author
Steve Thompson
committed
Added more usage examples to README
1 parent 1652909 commit dd53a23

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ getAndRemove.byType(
272272
```
273273
insert.at(index, values: any[]): PublicArrayInserter
274274
// inserts values at index. index can be negative or positive.
275+
// If positive, existing items beginning at that index will be pushed to the right to
276+
// make room. If negative, existing items ending at that index will be pushed to the
277+
// left to make room.
275278
276279
insert.middle(values: any[], offset = 0): PublicArrayInserter
277280
// inserts values in middle of this.data .
@@ -573,6 +576,27 @@ arr.data = [item1, item2, item3, ...];
573576
574577
// changing the array content without breaking its memory reference:
575578
arr.set( [item1, item2, item3, ...] );
579+
580+
// using .append() instead of .push():
581+
arr.append(['goodbye']); // now the last item in arr.data is 'goodbye'
582+
583+
// using .prepend() instead of .unshift():
584+
arr.prepend(['hello']); // now the first item in arr.data is 'hello'
585+
586+
// checking if array has a particular item:
587+
arr.data = ['a', 'q', 'r', 'z', 'x'];
588+
if (arr.has('q')) console.log('yes'); // --> 'yes'
589+
590+
// checking if array has exact sequence of adjacent items:
591+
arr.data = [3,6,9,12,11,3,5,1];
592+
if (arr.hasAdjacent([9,12,11,3])) console.log('yes'); // --> 'yes'
593+
594+
// removing any items that aren't numbers and putting the numbers in order:
595+
arr.filter.byType('number');
596+
arr.sort.numbersAscending();
597+
598+
// removing and returning dirty 4-letter words:
599+
let dirtyWords = arr.getAndRemove.byTest((item) => isString(item) && item.length === 4);
576600
```
577601

578602
## Performance

dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var __extends = (this && this.__extends) || (function () {
55
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
66
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
77
return extendStatics(d, b);
8-
}
8+
};
99
return function (d, b) {
1010
extendStatics(d, b);
1111
function __() { this.constructor = d; }

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)