Home>

You need to implement a function that takes two array on the input and filters the first according to the second according to the specified rules.

Examples:

array to filter
Const Response= [
  {
    Name: {
      FIRST: 'TestFirst',
      Last: 'testlast2',
    }
    }
    Goal: 'goal_1',
    ISTRUE: TRUE,
  }
  {
    Name: {
      FIRST: 'testfirst2',
      Last: 'testlast2',
    }
    Goal: 'goal_2',
    ISTRUE: TRUE,
  }
];
array with filters
Const Filter= [
  {
    Property: 'name.first',
    in_values: ['testfirst', 'testfirst2'],
  }
  {
    Property: 'name.last',
    not_in_values: ['testlast2'],
  }
  {
    Property: 'Goal',
    In_Values: ['goal_1', 'goal_2'],
  }
  {
    Property: 'iStrue',
    IN_VALUES: [TRUE],
  }
];
Resluting array
Const Result= [
  {
    Name: {
      FIRST: 'TEST',
      Last: 'Test',
    }
    Goal: 'goal_1',
    ISTRUE: TRUE,
  }
];

Property -The field to be checked.

in_Values -array of values. If there is at least one coincidence, then the recording falls into the resulting array

not_in_values -array of values. If there is at least one coincidence, then recording not falls into the resulting array

If all the "rules" filtering were used successfully, then the entry falls into the resulting array.

nesting can be any. A universal solution is required. In Response, there may be objects not only from the example. Inside the array objects of the same structure.

What exactly did not work?

santavital2021-09-22 03:12:09

@Santavital beautiful solution

Alexandr2021-09-22 03:12:09

It is necessary to show your decision; otherwise it is perceived not as a question, but as a request, instead of me ...

santavital2021-09-22 03:12:09