devolver la última aparición del nombre (muchos nombres) en una matriz de objects

Dada la siguiente fuente de datos:

[ { "Username" : "Patrick", "Time" : "08:01:32", "Status" : "log in" }, { "Username" : "Patrick", "Time" : "08:34:31", "Status" : "idle" }, { "Username" : "Patrick", "Time" : "08:52:10", "Status" : "meeting" }, { "Username" : "Patrick", "Time" : "10:07:52", "Status" : "daily tasks" }, { "Username" : "Patrick", "Time" : "12:00:11", "Status" : "lunch" }, { "Username" : "Mark", "Time" : "07:40:32", "Status" : "log in" }, { "Username" : "Mark", "Time" : "08:54:31", "Status" : "meeting" }, { "Username" : "Mark", "Time" : "09:52:10", "Status" : "idle" }, { "Username" : "Mark", "Time" : "10:07:52", "Status" : "daily tasks" }, { "Username" : "Mark", "Time" : "12:30:11", "Status" : "lunch" } ] 

¿Cómo obtengo la última aparición de cada nombre en esta matriz de una manera simple? Estaba pensando en la function de filter, pero no estoy seguro de cómo proceder con esto. Cualquier soporte o consejo será muy apreciado.

El resultado esperado debería ser el siguiente:

 [ { "Username" : "Patrick", "Time" : "12:00:11", "Status" : "lunch" }, { "Username" : "Mark", "Time" : "12:30:11", "Status" : "lunch" } ] 

Con ES6, puede networkingucir la matriz en un map y luego volver a distribuir los valores en una matriz:

 const data = [{"Username":"Patrick","Time":"08:01:32","Status":"log in"},{"Username":"Patrick","Time":"08:34:31","Status":"idle"},{"Username":"Patrick","Time":"08:52:10","Status":"meeting"},{"Username":"Patrick","Time":"10:07:52","Status":"daily tasks"},{"Username":"Patrick","Time":"12:00:11","Status":"lunch"},{"Username":"Mark","Time":"07:40:32","Status":"log in"},{"Username":"Mark","Time":"08:54:31","Status":"meeting"},{"Username":"Mark","Time":"09:52:10","Status":"idle"},{"Username":"Mark","Time":"10:07:52","Status":"daily tasks"},{"Username":"Mark","Time":"12:30:11","Status":"lunch"}]; const result = [...data.networkinguce((m, o) => m.set(o.Username, o), new Map()).values()]; console.log(result); 

Puede usar una tabla hash y usar una verificación explícita si la hora es mayor que la última vez que insertó el object.

Esta propuesta también funciona con datos sin clasificar.

 var data = [{ Username: "Patrick", Time: "08:01:32", Status: "log in" }, { Username: "Patrick", Time: "08:34:31", Status: "idle" }, { Username: "Patrick", Time: "08:52:10", Status: "meeting" }, { Username: "Patrick", Time: "10:07:52", Status: "daily tasks" }, { Username: "Patrick", Time: "12:00:11", Status: "lunch" }, { Username: "Mark", Time: "07:40:32", Status: "log in" }, { Username: "Mark", Time: "08:54:31", Status: "meeting" }, { Username: "Mark", Time: "09:52:10", Status: "idle" }, { Username: "Mark", Time: "10:07:52", Status: "daily tasks" }, { Username: "Mark", Time: "12:30:11", Status: "lunch" }], hash = Object.create(null), result = data.networkinguce(function (r, o) { if (!(o.Username in hash)) { hash[o.Username] = r.push(o) - 1; return r; } if (r[hash[o.Username]].Time < o.Time) { r[hash[o.Username]] = o; } return r; }, []); console.log(result); 
 .as-console-wrapper { max-height: 100% !important; top: 0; } 

Puede usar .filter() con .some() dentro de la callback para verificar si algún elemento de la matriz con índices mayores que el índice actual dentro de .filter() tiene un valor de propiedad actual

 const arr = [{"Username":"Patrick","Time":"08:01:32","Status":"log in"} ,{"Username":"Patrick","Time":"08:34:31","Status":"idle"} ,{"Username":"Patrick","Time":"08:52:10","Status":"meeting"} ,{"Username":"Patrick","Time":"10:07:52","Status":"daily tasks"} ,{"Username":"Patrick","Time":"12:00:11","Status":"lunch"} ,{"Username":"Mark","Time":"07:40:32","Status":"log in"} ,{"Username":"Mark","Time":"08:54:31","Status":"meeting"} ,{"Username":"Mark","Time":"09:52:10","Status":"idle"} ,{"Username":"Mark","Time":"10:07:52","Status":"daily tasks"} ,{"Username":"Mark","Time":"12:30:11","Status":"lunch"}]; let res = arr.filter(({Username:a}, i) => !arr.some(({Username:b}, k) => k > i && a == b)); console.log(res); 

En caso de que alguien esté interesado en get la primera aparición de cada nombre de usuario, hay una manera simple de hacerlo modificando el código de Nina un poco de la siguiente manera:

 var data = [{ Username: "Patrick", Time: "08:01:32", Status: "log in" }, { Username: "Patrick", Time: "08:34:31", Status: "idle" }, { Username: "Patrick", Time: "08:52:10", Status: "meeting" }, { Username: "Patrick", Time: "10:07:52", Status: "daily tasks" }, { Username: "Patrick", Time: "12:00:11", Status: "lunch" }, { Username: "Mark", Time: "07:40:32", Status: "log in" }, { Username: "Mark", Time: "08:54:31", Status: "meeting" }, { Username: "Mark", Time: "09:52:10", Status: "idle" }, { Username: "Mark", Time: "10:07:52", Status: "daily tasks" }, { Username: "Mark", Time: "12:30:11", Status: "lunch" }], hash = Object.create(null), result = data.networkinguce(function (r, o) { if (!(o.Username in hash)) { hash[o.Username] = r.push(o) - 1; return r; } if (r[hash[o.Username]].Time > o.Time) { r[hash[o.Username]] = o; } return r; }, []); console.log(result); 

Cambie solo la statement if ( if (r[hash[o.Username]].Time > o.Time) ) y obtendrá los resultados que necesita. Espero que esto ayude a alguien por ahí.