Improve handling of arrays in json

This commit is contained in:
Yarmo Mackenbach 2020-11-04 02:41:14 +01:00
parent fc66e8fce4
commit 18c8662db8

View file

@ -7,6 +7,13 @@ const runOnJson = (res, proofData, checkPath, checkClaim, checkRelation) => {
return res
}
if (Array.isArray(proofData)) {
proofData.forEach((item, i) => {
res = runOnJson(res, item, checkPath, checkClaim, checkRelation)
})
return res
}
if (checkPath.length == 0) {
switch (checkRelation) {
default:
@ -30,18 +37,7 @@ const runOnJson = (res, proofData, checkPath, checkClaim, checkRelation) => {
return res
}
if (Array.isArray(proofData)) {
proofData.forEach((item, i) => {
res = runOnJson(res, item, checkPath, checkClaim, checkRelation)
})
} else if (Array.isArray(proofData[checkPath[0]])) {
proofData[checkPath[0]].forEach((item, i) => {
res = runOnJson(res, item, checkPath.slice(1), checkClaim, checkRelation)
})
} else {
res = runOnJson(res, proofData[checkPath[0]], checkPath.slice(1), checkClaim, checkRelation)
}
return res
}