0

Just wondering, what is the best way to go about "sorting" an array to the following:

I have the array as [1,1,1,1,2,2,2,2], how would I sort it so it goes:

[1,2,1,2,1,2,1,2]

I cannot think of the phrase or a method to do this.

This is done in angularjs/can use jquery.

9
  • Angular and jQuery to sort an array? Why not use .sort()? Commented Nov 1, 2017 at 16:38
  • Is the starting array always half and half like your example? Commented Nov 1, 2017 at 16:38
  • developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Nov 1, 2017 at 16:38
  • 1
    So split in half and interweave? Doubt you want to sort. Commented Nov 1, 2017 at 16:40
  • 1
    evolutionxbox, Yoda sorting an re-arranging are different. TylerWilson you probably want to simply loop from both ends and append values one at a time Commented Nov 1, 2017 at 16:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.