0

Okay, I don't even know how to phrase this question, let me begin with small set. Suppose, I have 3 input data fields:

let user= 'P' (Primary) or 'S' (secondary)
let key = k1 (random key)
let verification= passed or failed

Now the value of the key depends on the user and verification

if(user=='P' && verification === 'passed)
  return {k1:A}
if(user=='S' && verification === 'passed)
  return {k1:S}
if(user=='P' && verification === 'failed)
  return {k1:F}

Now, imagine possible number of values for user are 10, verification 3 and keys are 10. Then this code becomes ugly. Similarly, it would be if I choose Array. This would be simple if I have to write server-side app with DB. Then I could simply fire the query. What would you think the best way to solve this for browser JS app?

Again, just looking for ideas and not code. Thanks!

Vish
  • 155
  • 2
  • 4
  • 16

1 Answers1

0

Thanks to @JavaScript:

  • json object store
  • access/query like an array
const flagValues = {
    ssnValidation: {
        Primary: { Passed: 'P', Failed: 'F', NotAttempted: 'NA' },
        Secondary: { Passed: 'P', Failed: 'F', NotAttempted: 'NA' },
        AuthorizedUser: { Passed: 'P', Failed: 'F', NotAttempted: 'NA' },
        BusinessUser: { Passed: 'P', Failed: 'F', NotAttempted: 'NA' },
        Other: { Passed: 'P', Failed: 'F', NotAttempted: 'NA' },
    },
    dobValidation: {
        Primary: { Passed: 'P', Failed: 'F', NotAttempted: 'NA' },
        Secondary: { Passed: 'P', Failed: 'F', NotAttempted: 'NA' },
        AuthorizedUser: { Passed: 'P', Failed: 'F', NotAttempted: 'NA' },
        BusinessUser: { Passed: 'P', Failed: 'F', NotAttempted: 'NA' },
        Other: { Passed: 'P', Failed: 'F', NotAttempted: 'NA' },
    }
}

flagValues["ssnValidation"]["AuthorizedUser"]["Failed"]
Vish
  • 155
  • 2
  • 4
  • 16