Created
November 9, 2021 19:51
-
-
Save Noitabara/415f02e9e276852f508d63e07514771c to your computer and use it in GitHub Desktop.
Will return an array in which the first element is sent to the back of the array and the others moved forward. Does not mutate origional array.
This file contains 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
/** | |
* Functional queue shift. Will return an array in which the first element is sent to the back of the array and the others moved forward. Does not mutate origional array. | |
* @param arr The array you want to shift. | |
* @returns The new shifted array. | |
*/ | |
function shiftQueue<T>(arr: Array<T>): Array<T> { | |
const [first , ...rest] = arr | |
return [...rest, first] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment