From 18c8662db8eb03b7760088d03bac9c9845074ae7 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Wed, 4 Nov 2020 02:41:14 +0100 Subject: [PATCH] Improve handling of arrays in json --- src/claimVerification.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/claimVerification.js b/src/claimVerification.js index ddd291a..7290f7d 100644 --- a/src/claimVerification.js +++ b/src/claimVerification.js @@ -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) - } - + res = runOnJson(res, proofData[checkPath[0]], checkPath.slice(1), checkClaim, checkRelation) return res }