Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
Array iteration inside array of objects

I need to write a function that will go through all array objects and check wether at least one object has inner array where all objects have boolean value set to true. Please see code examples for better understanding.

Example 1

const array = [
  {
    id: 1,
    innerArray: [
      { innerId: 1, clicked: false },
      { innerId: 2, clicked: false },
    ],
  },
  {
    id: 2,
    innerArray: [
      { innerId: 1, clicked: true },
      { innerId: 2, clicked: false },
    ],
  },
  {
    id: 3,
    innerArray: [
      { innerId: 1, clicked: true },
      { innerId: 2, clicked: true }, 
    ],
  },
];

functionToBeCreated(array); // Output: true - because item with id 3 has innerArray where all items have "clicked: true".

Example 2

const array = [
  {
    id: 1,
    innerArray: [
      { innerId: 1, clicked: false },
      { innerId: 2, clicked: false },
    ],
  },
  {
    id: 2,
    innerArray: [
      { innerId: 1, clicked: true },
      { innerId: 2, clicked: false },
    ],
  },
  {
    id: 3,
    innerArray: [
      { innerId: 1, clicked: false },
      { innerId: 2, clicked: true }, 
    ],
  },
];

functionToBeCreated(array); // Output: false - because no item has innerArray where all items have "clicked: true".

Do you have maybe any ideas how it ca be achieved?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

this way...

const ToBeCreated = arr =>
   arr.some( el => el.innerArray.every(z => z.clicked));

const arrayTRUE = 
  [ { id: 1, innerArray: 
      [ { innerId: 1, clicked: false } 
      , { innerId: 2, clicked: false }
      ] } 
  , { id: 2, innerArray: 
      [ { innerId: 1, clicked: true  } 
      , { innerId: 2, clicked: false } 
    ] } 
  , { id: 3, innerArray: 
      [ { innerId: 1, clicked: true } 
      , { innerId: 2, clicked: true } 
  ] } ] 

const arrayFALSE = 
  [ { id: 1, innerArray: 
      [ { innerId: 1, clicked: false } 
      , { innerId: 2, clicked: false }
      ] } 
  , { id: 2, innerArray: 
      [ { innerId: 1, clicked: true  } 
      , { innerId: 2, clicked: false } 
    ] } 
  , { id: 3, innerArray: 
      [ { innerId: 1, clicked: false } 
      , { innerId: 2, clicked: true  } 
  ] } ] 

// test 
console.log( ToBeCreated(arrayTRUE ) ) 
console.log( ToBeCreated(arrayFALSE) ) 

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda