Skip to content

shift

Shift array items by n steps

145 bytes

Usage

Given a list of items, return an array that shift right n positions.

import * as
import _
_
from 'radashi'
const
const arr: number[]
arr
= [1, 2, 3, 4, 5, 6, 7, 8, 9]
import _
_
.
shift<number>(arr: readonly number[], n: number): number[]
export shift

Shifts array items by n steps. If n is greater than 0, items will shift n steps to the right. If n is less than 0, items will shift n steps to the left.

@seehttps://radashi.js.org/reference/array/shift

@example

shift([1, 2, 3], 1) // [3, 1, 2]
shift([1, 2, 3], -1) // [2, 3, 1]

@version12.1.0

shift
(
const arr: number[]
arr
, 3) // => [7, 8, 9, 1, 2, 3, 4, 5, 6]