I have an array
of objects
, each object has timestamp
field. Now I'd like to sort this array starting from bottom to top by timestamp
field, and as a result I need sorted array and also index
of where below of it inclusively algorithm made changes.
Example:
Array = [
{timestamp: 1}, //index 0
{timestamp: 2}, //index 1
{timestamp: 3}, //index 2
{timestamp: 4}, //index 3
{timestamp: 5}, //index 4
{timestamp: 6}, //index 5
{timestamp: 10}, //index 6
{timestamp: 8}, //index 7
{timestamp: 9}, //index 8
{timestamp: 7} //index 9
];
const result = magicSort(array);
result.array == [
{timestamp: 1},
{timestamp: 2},
{timestamp: 3},
{timestamp: 4},
{timestamp: 5},
{timestamp: 6},
{timestamp: 7},
{timestamp: 8},
{timestamp: 9},
{timestamp: 10}
];
result.changesMadeFromIndexToEnd == 6
How can I do this?