function filter(val) {
if (!(val instanceof Object)) {
return val;
}
const filtered = Object
.entries(val)
.map(n => [ n[0], filter(n[1]) ])
.filter(n => n[1]);
return filtered.length
? val instanceof Array
? filtered.map(n => n[1])
: Object.fromEntries(filtered)
: null;
}
const isValid = arr =>
arr.every(n => Object.values(n).every(m => !m.isRequired || m.value));
function isValid(arr) {
for (const n of arr) {
for (const k in n) {
if (n.hasOwnProperty(k) && n[k].isRequired && !n[k].value) {
return false;
}
}
}
return true;
}