Skip to content

Instantly share code, notes, and snippets.

@parwatcodes
Created September 19, 2017 04:03
Show Gist options
  • Save parwatcodes/58726651e83401ac331a4c020948fe77 to your computer and use it in GitHub Desktop.
Save parwatcodes/58726651e83401ac331a4c020948fe77 to your computer and use it in GitHub Desktop.
const currentMonth = 8;
const data = [{
employee: 70,
month: 0,
year: 2017,
id: 3,
createdAt: '2017-09-15T09:42:37.000Z',
updatedAt: '2017-09-15T09:42:37.000Z',
organization: 41,
version: 1
},
{
employee: 70,
month: 4,
year: 2017,
id: 4,
createdAt: '2017-09-15T09:59:28.000Z',
updatedAt: '2017-09-15T09:59:28.000Z',
organization: 41,
version: 2
},
{
employee: 70,
month: 4,
year: 2017,
id: 5,
createdAt: '2017-09-15T10:00:35.000Z',
updatedAt: '2017-09-15T10:00:35.000Z',
organization: 41,
version: 3
},
{
employee: 70,
month: 4,
year: 2017,
id: 6,
createdAt: '2017-09-15T10:01:18.000Z',
updatedAt: '2017-09-15T10:01:18.000Z',
organization: 41,
version: 4
},
{
employee: 70,
month: 4,
year: 2017,
id: 7,
createdAt: '2017-09-15T10:07:11.000Z',
updatedAt: '2017-09-15T10:07:11.000Z',
organization: 41,
version: 5
},
{
employee: 70,
month: 4,
year: 2017,
id: 8,
createdAt: '2017-09-15T10:40:11.000Z',
updatedAt: '2017-09-15T10:40:11.000Z',
organization: 41,
version: 6
},
{
employee: 70,
month: 4,
year: 2017,
id: 9,
createdAt: '2017-09-15T10:40:58.000Z',
updatedAt: '2017-09-15T10:40:58.000Z',
organization: 41,
version: 7
}, {
employee: 70,
month: 7,
year: 2017,
id: 10,
createdAt: '2017-09-15T10:40:58.000Z',
updatedAt: '2017-09-15T10:40:58.000Z',
organization: 41,
version: 6
}, {
employee: 70,
month: 7,
year: 2017,
id: 11,
createdAt: '2017-09-15T10:40:58.000Z',
updatedAt: '2017-09-15T10:40:58.000Z',
organization: 41,
version: 7
}, {
employee: 73,
month: 8,
year: 2017,
id: 11,
createdAt: '2017-09-15T10:40:58.000Z',
updatedAt: '2017-09-15T10:40:58.000Z',
organization: 41,
version: 1
}];
// here there is employee 73 for moth 8 only, so it should return this month only,
// if i enter a new record for same employee,
// suppose
{
employee: 73,
month: 4,
year: 2017,
id: 11,
createdAt: '2017-09-15T10:40:58.000Z',
updatedAt: '2017-09-15T10:40:58.000Z',
organization: 41,
version: 1
}
// then the same process goes on, if current month is 5 give me record of month 4, if current month is 3 then there is no
// lowest closet record to it, so take closet highest record which is of month 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment