Necesito escribir una función que pase por todos los objetos de la matriz y verifique si al menos un objeto tiene una matriz interna donde todos los objetos tienen un valor booleano establecido en verdadero. Consulte los ejemplos de código para una mejor comprensión.
Ejemplo 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".Ejemplo 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".¿Tiene alguna idea de cómo se puede lograr?
Por aquí...
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) )