Skip to content

Instantly share code, notes, and snippets.

@mariusom
Created December 19, 2017 17:54
Show Gist options
  • Select an option

  • Save mariusom/d492cd2a4b838b77869a4e985be47d8d to your computer and use it in GitHub Desktop.

Select an option

Save mariusom/d492cd2a4b838b77869a4e985be47d8d to your computer and use it in GitHub Desktop.

Revisions

  1. mariusom created this gist Dec 19, 2017.
    41 changes: 41 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    var output = [];
    //var dataSource = app.models.Employee.newQuery().run();
    var dataSource = [
    {
    timestamp: "2017-09-12 13:49",
    fullname: "John",
    emailAddress: "[email protected]"
    //....
    },
    {
    timestamp: "2017-06-12 13:49",
    fullname: "John",
    emailAddress: "[email protected]"
    },
    {
    timestamp: "2017-09-12 13:49",
    fullname: "Johhyn",
    emailAddress: "[email protected]"
    }
    ];

    for (var i = 0; i < dataSource.length; i++) {
    var employee = dataSource[i];

    var foundOutputEmployeeIndex = null;

    for (var j = 0; j < output.length; j++) {
    if (
    output[j].emailAddress === employee.emailAddress &&
    foundEmp.timestamp < employee.timestmap
    ) {
    output[j] = employee;
    }
    }

    if (foundOutputEmployeeIndex != null) {
    output.push(employee);
    }
    }

    console.log(output);