Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
I need to determine a set of users using X amount of modules

The exercise has two parts, A and B.

A is simple, it requires to check the modules that each user makes use of and return an object with the following format. This part is solved.

{
 'auth_module': {
    'authn.provider_1': ['./u1.json', './u2.json']
    'authn.provider_2': ['./u3.json', './u4.json', './u5.json']
  },
'content_module': {
    'authz.provider_1': ['./u1.json', './u3.json'],
    'authz.provider_2': ['./u2.json', './u4.json'],
    'authz.provider_3': ['./u5.json']
  }
}

Now, in part B I need help to solve this:

"Determine a group of users (taken from part A) that together use all the available modules"

The example output is in this format:

['./u1.json', './u4.json', './u5.json']

I genuinely have no clue on how to solve this, so any kind of help will be really appreciated.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

  • Using Object#entries and Array#reduce, iterate over the auth_module pairs while updating a list of target users
    • In each iteration, parse the provider id and get the list of content users for that provider if any
    • Using Array#forEach, iterate over the current auth users and update the target list with common ones between the two
  • In case there were content-only providers only, we need to push the users to the list as well. Using Object#entries and Array#forEach, iterate over the content_module pairs
    • In each iteration, check if the current provider id is not in the auth_module to add its users
  • Finally, return the list of unique users using Set

const _getUsers = modules => {
  const authIdPrefix = 'authn.', contentIdPrefix = 'authz.';
  const { 'auth_module': authModule, 'content_module': contentModule } = modules;
  
  const users = Object.entries(authModule)
    .reduce((list, [authProvider, authUsers]) => {
      const providerId = authProvider.substring(authIdPrefix.length);
      const contentUsers = contentModule[`${contentIdPrefix}${providerId}`] ?? [];
      authUsers.forEach(user => {
        if(contentUsers.includes(user)) {
          list.push(user);
        }
      });
      return list;
    }, []);

  Object.entries(contentModule)
    .forEach(([contentProvider, contentUsers]) => {
      const providerId = contentProvider.substring(contentIdPrefix.length);
      if(!authModule[`${authIdPrefix}${providerId}`]) {
        users.push(...contentUsers);
      }
    });

  return [...new Set(users)];
}

const modules = {
  'auth_module': {
    'authn.provider_1': ['./u1.json', './u2.json'],
    'authn.provider_2': ['./u3.json', './u4.json', './u5.json']
  },
  'content_module': {
    'authz.provider_1': ['./u1.json', './u3.json'],
    'authz.provider_2': ['./u2.json', './u4.json'],
    'authz.provider_3': ['./u5.json']
  }
};
console.log( _getUsers(modules) );

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!