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

149
Visualizações
Javascript - Online Coding assessment to mask credit cards numbers with #

I got the below coding assessment question in Javascript. I tried my best to solve but there are few edge cases I missed. I need help to identify those missing cases

Usually when you buy something, you're asked whether your credit card number, phone number or answer to your most secret question is still correct. However, since someone could look over your shoulder, you don't want that shown on your screen. Instead, we mask it.

This is what I tried so far

function maskify (cc) {
  if (cc.length < 6) {
      let reversed = reverse(cc);
      let newString = '';
      for (let i = 0; i < reversed.length; i++) {
        if (i < 4) {
          newString += reversed[i];
        } else {
          newString += '#';
        }
      }
      return reverse(newString);

Output

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is my solution:

function maskify (cc) {
  // If less than 6 characters return full number
  if (cc.length < 6)
    return cc;
    
  // Take out first character
  let firstChar = cc.charAt(0);
  cc = cc.slice(1);
    
  // Replace characters except last 4
  cc = cc.replace(/\d(?=.{4,}$)/g, '#');
  
  // Add first character back
  cc = firstChar + cc;
  
  return cc;
}

// Run every example number
const tests = ["4556364607935616", "4556-3646-0793-5616", 
                "64607935616", "ABCD-EFGH-IJKLM-NOPQ",
                "A1234567BCDEFG89HI", "12345", "", "Skippy"];

tests.forEach((number) => console.log(`Testing: ${number} - Output: ${maskify(number)}`));

I ran it with all the numbers of your example and it gets the correct output.

about 4 years ago · Juan Pablo Isaza 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