mercredi 4 avril 2018

Comparing multiple values from two arrays and storing the results in a new array

I need to go over a sheet, take employees start date and end date which I successfully receive as props, format them in a proper way (different sheets = different date formats), that goes well, but depending on the date clicked I need to display a list of employees that worked in that period, meaning if they stopped working after that particular date, they'll be listed, but if they started after that date, they wouldn't be listed.

Imagine a Reports component with all different reports listed (depending on the date), when a user clicks one he should be forwarded to details component where I need to list all the active employees in that particular month.

const { year } = this.props.history.location.state.item;
    const { month } = this.props.history.location.state.item;

    const selectedMonth = moment().month(month).format("MM");

    // it's a number 201703
    const finalSelect = parseInt(year + selectedMonth);

    // BASIC FORMATTING:
   const {employees, reports} = this.props;  
 const renderActive = [];

    employees.map(emp => {
        if( finalSelect > parseInt(moment(emp.startdate).format('YYYYMM')) 
        && finalSelect > parseInt(moment(emp.enddate).format('YYYYMM'))) {
            renderActive.push(emp);
        }});              

    /* employees.map(emp => {
        if( emp.enddate == undefined) {
            renderActive.push(emp);
        }}); */

    const unique = renderActive
        .map( item => item )
        .filter( ( item, idx, arr ) => arr.indexOf( item ) == idx ) 

        console.log(unique);

** So what I [think] that I need to accomplish is: **

Start date needs to be higher the selected Date and the end date also needs to be higher than the one selected. And if there's no endDAte it's undefined, so I need to take that into account too.

startDate > selectedReport < endDate

THANK YOU GUYS IN ADVANCE :)

Aucun commentaire:

Enregistrer un commentaire