joi icon indicating copy to clipboard operation
joi copied to clipboard

Comparing arrays of objects by key or predicate

Open itoed opened this issue 6 years ago • 1 comments

Support plan

  • which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise): Community
  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): yes

Context

  • node version: 13.6.0
  • module version: 16.1.5
  • environment (e.g. node, browser, native): browser
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information: Webpack and Babel

How can we help?

I would like to validate the following object such that the names in xs and the names inys are the same list when ordered.

const inputData = {
  xs: [
    { id: 'x1', name: 'A' },
    { id: 'x2', name: 'B' },
    { id: 'x3', name: 'C' },
    { id: 'x4', name: 'D' }, // Invalid: No match in ys
  ],
  ys: [
    { id: 'y1', name: 'A' },
    { id: 'y2', name: 'B' },
    { id: 'y3', name: 'C' },
    { id: 'x4', name: 'E' }, // Invalid: No match in xs
  ],

Is there a built-in to validate this?

itoed avatar Mar 04 '20 01:03 itoed

Nope.

hueniverse avatar Mar 09 '20 06:03 hueniverse