While Loop Structure Javascript Array Sort