Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda