Skip to content

Instantly share code, notes, and snippets.

@kaleem-elahi
Created February 12, 2019 10:55
Show Gist options
  • Select an option

  • Save kaleem-elahi/4a469c27bc06766e98cae17bbb779c36 to your computer and use it in GitHub Desktop.

Select an option

Save kaleem-elahi/4a469c27bc06766e98cae17bbb779c36 to your computer and use it in GitHub Desktop.
To sort Job details date's with Present(Current) employer(company)
let final = [];
const currentCompany = this.props.profile.position_history.filter(d => d.is_current_employer); // current company
// Sorted latest to old job position
const otherSortedComapny = this.props.profile.position_history.sort((a, b) => {
if (a.end_date) {
return new Date(b.end_date) - new Date(a.end_date);
}
return new Date(b.start_date) - new Date(a.start_date);
}).filter(d => !d.is_current_employer);
// Merge both and see the Magic
final = [...currentCompany, ...otherSortedComapny];
console.log(final);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment