0

in the action of my reduceur I get an array, that I would like to filter with another table, I would like to check certain value how to include the other table in the filter? (without return) because i will put a le

dbz: [{
      min: 300
      max: 9000
      name: 'goku'
    },

    {
      min: 200
      max: 7000
      name: 'vegeta'
    },

  ],

  dbs: [{
      min: 200
      max: 7000
      name: 'picollo'
    },

    {
      min: 300
      max: 9000
      name: 'gohan'
    },

    {
      min: 20
      max: 800
      name: 'trunks'
    },

    {
      min: 10
      max: 700
      name: 'goten'
    },

  ],


  let samepower = dbs.filter(({
    sayien
  }) => sayien.min !== dbz.min && sayien.max !== dbz.max);

the idea is to have an array with only 'goten' and 'trunks' .. to remove 'gohan' and 'picollo' because they have a 'max' and 'min' equal to 'goku' and ' vegeta'

1 Answer 1

1

You can use array's method filter and some to simplify the answer.

const filtered = (dbs, dbz) => {
  return dbs.filter((ii) =>
    dbz.some((jj) => ii.min === jj.min && ii.max === jj.max)
  );
};

const database = {
  dbz: [
    { min: 300, max: 9000, name: "goku" },
    { min: 200, max: 7000, name: "vegeta" },
  ],
  dbs: [
    { min: 200, max: 7000, name: "picollo" },
    { min: 300, max: 9000, name: "gohan" },
    { min: 20, max: 800, name: "trunks" },
    { min: 10, max: 700, name: "goten" },
  ],
};
console.log(filtered(database.dbs, database.dbz));

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.