Skip to content

Instantly share code, notes, and snippets.

@Noitabara
Created November 9, 2021 19:51
Show Gist options
  • Save Noitabara/415f02e9e276852f508d63e07514771c to your computer and use it in GitHub Desktop.
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.
/**
* 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