mardi 22 janvier 2019

Can't return a value in JavaScript

I have this really weird thing going on. So I made a filter system that worked on a basic file just to build it and now I want to implement it in the original project but my value just doesn't return, do you se why? Ill show a example of the original vs the implementated so you can see what's wrong.

Original:

const filterData = (locatie, soort, dag) => {
  let filteredActs = acts;
  console.log(acts);

  if (locatie !== "alle") {
    locatie = parseInt(locatie);
    filteredActs = filteredActs.filter(act => act.locatie === locatie);
  }

  if (soort !== "alle") {
    filteredActs = filteredActs.filter(act => act.soort === soort);
  }

  if (dag !== "alle") {
    filteredActs = filteredActs.filter(act => act.day === dag);
  }
  // …

  console.log(filteredActs);
  return filteredActs;
};

Implemented:

const filterData = (locatie, soort, dag) => {
  let filteredActs = acts;

  if (locatie !== `alle`) {
    locatie = parseInt(locatie);
    filteredActs = filteredActs.filter(act => act.locatie === locatie);
  }

  if (soort !== `alle`) {
    filteredActs = filteredActs.filter(act => act.soort === soort);
  }

  if (dag !== `alle`) {
    filteredActs = filteredActs.filter(act => act.dag.slice(- 2) === dag);
  }

  console.log(filteredActs);
  return filteredActs;
};

This is the log result when I log in the filterData function

Aucun commentaire:

Enregistrer un commentaire