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

216
Visualizações
My code passes all my tests but some how edabit is not approving it
function bitwiseAND(n1, n2) {
  let a = n1.toString(2).padStart(8, "0");
  let b = n2.toString(2).padStart(8, "0");
  let x = "";
  for (let i = 0; i < 8; i++) {
     if (+a[i] === 1 && +a[i] === +b[i]) x = x + "1";
     else x = x + "0";
}
return +x
}

function bitwiseOR(n1, n2) {
  let a = n1.toString(2).padStart(8, "0");
  let b = n2.toString(2).padStart(8, "0");
  let x = "";
  for (let i = 0; i < 8; i++) {
    if (+a[i] === 1 || +b[i] === 1) x = x + "1";
    else x = x + "0";
}
return +x
}

function bitwiseXOR(n1, n2) {
  let a = n1.toString(2).padStart(8, "0");
  let b = n2.toString(2).padStart(8, "0");
  let x = "";
  for (let i = 0; i < 8; i++) {
    if ((+a[i] === 1 && +b[i] === 0) || (+a[i] === 0 && +b[i] === 1))
      x = x + "1";
    else x = x + "0";
}
return +x
}

This is link to the challenge

challenge was to Write three functions to calculate the bitwise AND, bitwise OR and bitwise XOR of two numbers.

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

0

Your code is good, the only thing that is missing is to convert the binary to an integer on your return values.

Insted of

return +x

Try

return parseInt(x, 2)
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