Home > @josh-brown/vector > VectorBuilder > shift
Constructs a vector whose entries match the input vector, but offset by a given amount
Signature:
shift(vector: Vector<S>, offset?: number, reverse?: boolean): V;|
Parameter |
Type |
Description |
|---|---|---|
|
vector |
Vector<S> |
The vector whose entries to use |
|
offset |
number |
(Optional) The amount by which to shift the indices |
|
reverse |
boolean |
(Optional) Shift entries backward rather than forward |
Returns:
V
const original = vectorBuilder.fromArray([1, 2, 3]);
const rightOne = vectorBuilder.rotate(original); // [2, 3, 1];
const rightTwo = vectorBuilder.rotate(original, 2); // [3, 1, 2];
const leftOne = vectorBuilder.rotate(original, 1, true); // [3, 1, 2];