My issue is very simple to explain, but figuring out the most efficient way of doing it is proving difficult.
I am trying to reorder an array starting at a particular index in the array.
What I have:
var array = [1,2,3,4,5];
What I want:
array = [3,4,5,1,2];
What I've done:
var array = [1,2,3,4,5]; var arr1 = array.slice(array.indexOf(3), array.length); var arr2 = array.slice(0, array.indexOf(3)); arr1.push(arr2); var newArray = arr1.join(); // [3,4,5,1,2];
As you can see, there is quite a bit going on for what is seemingly a simple task. If you have any suggestions on how to improve this I'd be grateful. Either vanilla JS or Underscore/Lodash is fine.