Skip to content

Latest commit

 

History

History
40 lines (25 loc) · 659 Bytes

move.mdx

File metadata and controls

40 lines (25 loc) · 659 Bytes

import { Callout } from "nextra/components"; import REPL from "../../components/REPL";

It moves an array element from one index position to another.

Immutable: This does not mutate the given array.

Syntax

import { move } from '@opentf/std';

move(arr: T[], from: number, to: number): T[];

Usage

import { move } from "@opentf/std";

move([], 0, 1);

Examples

move([1, 2, 3], 0, 2); //=> [2, 3, 1]

move([1, 2, 3], 0, 5); //=> [2, 3, 1]

move([1, 2, 3], 5, 0); //=> [1, 2, 3]

Try

<REPL code={`const { move } = require('@opentf/std');

move([1, 2, 3], 0, 2);`} />