Skip to content

Latest commit

 

History

History
96 lines (47 loc) · 1.32 KB

File metadata and controls

96 lines (47 loc) · 1.32 KB

Home > @josh-brown/vector > VectorBuilder > shift

VectorBuilder.shift() method

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;

Parameters

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

Example

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];