У меня есть массив строк, которые мне нужны для сортировки этих строк на основе первых 4 чисел в каждой строке. Но как мне настроить эти числа для сортировки? Код работает нормально, мне просто нужно его отсортировать.
Я пробовал .substring, но я не думаю, что это правильный метод для этого.
var volunteers = [ '9.05', '16.29', '26.67', '0.00', '2.25' ]
getResults: function(volunteers) {
this.results = [];
for (var i = 0; i < volunteers.length; i++) {
var dayNames = this.data[i][3] || " ";
var result = (volunteers[i] + " additional volunteers are needed on day " + i +" " +dayNames);
this.results.push(result);
}
console.log(this.results)
return this.results;
}
//Expected
[ '26.67 additional volunteers are needed on day 2 Tuesday',
'16.29 additional volunteers are needed on day 1 Monday',
'9.05 additional volunteers are needed on day 0 Sunday',
'2.25 additional volunteers are needed on day 4 ',
'0.00 additional volunteers are needed on day 3 Wednesday' ]
//Actual
[ '9.05 additional volunteers are needed on day 0 Sunday',
'16.29 additional volunteers are needed on day 1 Monday',
'26.67 additional volunteers are needed on day 2 Tuesday',
'0.00 additional volunteers are needed on day 3 Wednesday',
'2.25 additional volunteers are needed on day 4 ' ]