var _ = require("lodash");

var analysis_state_data = [
{ "start_time": "2020-05-12 12:58:29", "end_time": "2020-05-12 13:02:06"},
// { "start_time": "2020-05-12 13:02:06",	"end_time": "2020-05-12 13:08:08"},
// { "start_time": "2020-05-12 13:08:08",	"end_time": "2020-05-12 13:08:21"},
// { "start_time": "2020-05-12 13:08:08",	"end_time": "2020-05-12 13:08:26"},
// { "start_time": "2020-05-12 13:08:21",	"end_time": "2020-05-12 13:08:57"},
// { "start_time": "2020-05-12 13:09:43",	"end_time": "2020-05-12 13:10:10"}
];

var dirty_index = _.findIndex( analysis_state_data, {start_time :_.last(analysis_state_data).start_time } );
print(dirty_index);
analysis_state_data = _.slice(analysis_state_data, 0, dirty_index);
print(JSON.stringify(analysis_state_data, null, ' '));

analysis_state_data = _.reduce(analysis_state_data, function(prev, curr, index){
    if (prev.length > 0) {
        if (curr.start_time == prev[prev.length - 1].start_time) {
            prev[prev.length - 1] = curr;
        } else {
            prev.push(curr);
        }
    } else {
        prev.push(curr);
    }
    return prev;
}, []);



print(JSON.stringify(analysis_state_data, null, ' '));