Skip to content

Instantly share code, notes, and snippets.

@kpunith8
Created November 11, 2020 10:49
Show Gist options
  • Save kpunith8/994631dbe47bac2f412a47d3b4b2d133 to your computer and use it in GitHub Desktop.
Save kpunith8/994631dbe47bac2f412a47d3b4b2d133 to your computer and use it in GitHub Desktop.
Finddem Problem to find the total experience of an employee
const _ = require('lodash')
const condidateProfile = {
experience: [
{
company: 'ABC',
startDate: 2020,
present: true
},
// {
// company: 'Microsoft',
// startDate: 2018,
// endDate: 2020,
// },
{
company: 'Apple',
startDate: 2015,
endDate: 2017,
},
{
company: 'Sony',
startDate: 2012,
endDate: 2014,
},
// {
// company: 'Findem',
// startDate: 2016,
// endDate: 2020,
// }
]
}
const experiencePerCompany = _.compact(_.map(condidateProfile.experience, item => {
if(item.present) {
return
} else {
return {
totalYearsWorked: item.endDate - item.startDate
}
}
}))
const totalExperience = _.reduce(experiencePerCompany, (acc, val) => acc + val.totalYearsWorked, 0)
//https://zoom.us/j/94889993924?pwd=RUtkZkw0V0NKeGZ3QmIwZmoxa1A0Zz09
//please join above link
console.log({totalExperience})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment