Last active
May 24, 2024 17:03
-
-
Save alekstar79/1226cf6a449f16f82a897cf7a04f7f2e to your computer and use it in GitHub Desktop.
Array Shift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function shift(arr, direction, n) | |
{ | |
const times = n > arr.length ? n % arr.length : n | |
return arr.concat(arr.splice(0, (direction > 0 ? arr.length - times : times))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment