how to rotate an array in javascript

Solutions on MaxInterview for how to rotate an array in javascript by the best coders in the world

showing results for - "how to rotate an array in javascript"
Solène
29 Jul 2018
1function arrayRotate(arr, reverse) {
2  if (reverse) arr.unshift(arr.pop());
3  else arr.push(arr.shift());
4  return arr;
5}
6