Вы можете разделить, получить счет и исходный индекс, отсортировать, посчитав и индексировать, наконец, взять объединенную строку.
var string = "My passion is to work towards my goal is the whole idea",
array = string.split(' '),
hash = array.reduce((o, k, index) => {
o[k] = { index, count: (k.match(/[aeiou]/g) || []).length };
return o;
}, {})
result = array
.sort((a, b) => hash[b].count - hash[a].count || hash[b].index - hash[a].index)
.join(' ');
console.log(result);