Skip to content

Dictionary symbol and iteration index #3856

Answered by dubzzz
adamxi asked this question in Q&A
Discussion options

You must be logged in to vote

You may try something like:

function fakerToArb(fakerGen) {
  return fc
    .integer()
    .noBias()
    .noShrink()
    .map(seed => {
      faker.seed(seed);
      return fakerGen();
    });
}

const countryCodeArb = fakerToArb(faker.address.countryCode);

const countrySettingsArb = fc.uniqueArray(
  fc.record({ code: countryCodeArb, active: fc.boolean() }),
  { minLength: 1, selector: country => country.code },
)
  .map(countries => {
    return {
      default: countries[0].code,
      ...Object.fromEntries(
        countries.map((country, index) => [country.code, { order: index, active: country.active }])
      )
    };
  });

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@dubzzz
Comment options

@dubzzz
Comment options

@adamxi
Comment options

Answer selected by adamxi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants