I'm puzzled by the fact that the console is displaying a sorted array in both logs. It doesn't make sense to me because it should not be sorted at the first log, right?
static reloadAndSortItems() {
let array = [];
const items = Store.getStoredItems();
items.forEach(function (item) {
// converting stored date back to date object
let episodeDate = Date.parse(item.episode);
let parsedEpisode = new Date(episodeDate);
array.push(parsedEpisode);
});
**// array should not be sorted at this point
console.log('not sorted', array);**
let tested = array.sort(function (a, b) {
return a - b
});
**// array should be sorted at this point
console.log('sorted', tested);**
}
The incoming array is out of order:
["2018-09-13T00:30:00.000Z","2018-09-14T05:25:00.000Z","2018-09-13T00:30:00.000Z","2018-09-11T01:30:00.000Z","2018-09-11T01:30:00.000Z"]