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

308
Visualizações
Write a function which return the digits

Given a varying number of integer arguments, return the digits that are not present in any of them.

Example:

[12, 34, 56, 78]  =>  "09"

[2015, 8, 26]     =>  "3479"

Note: the digits in the resulting string should be sorted.

Help please, how to do this with a short and simple code, which method should I use? RegEx for compare?

function unusedDigits(numbers) {

}

console.log(unusedDigits([12, 34, 56, 78])); 
console.log(unusedDigits([2015, 8, 26]));
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

First concatenate the numbers into a single string:

> [2015, 8, 26].join('')
'2015826'

Then remove them from '0123456789':

> [...'0123456789'].filter(ch => !'2015826'.includes(ch)).join('')
'3479'

function unusedDigits(numbers) {
  const s = numbers.join('');
  return [...'0123456789'].filter(ch => !s.includes(ch)).join('');
}

console.log(unusedDigits([12, 34, 56, 78])); 
console.log(unusedDigits([2015, 8, 26]));

For a more efficient way if the input is huge, you can create a Set of digits instead of joining into a string.

about 4 years ago · Juan Pablo Isaza Relatório

0

You could take a Set and remove unwanted digits.

function unused (array) {
    return Array
        .from([...array.join('')].reduce(
            (s, v) => (s.delete(v), s),
            new Set('0123456789')
        ))
        .join('')
}


console.log(unused([12, 34, 56, 78])); // "09"
console.log(unused([2015, 8, 26]));    // "3479"

An approach with short circuit

function unused (array) {
    const s = new Set('0123456789');
    [...array.join('')].every(v => (s.delete(v), s.size));
    return Array
        .from(s)
        .join('')
}


console.log(unused([12, 34, 56, 78])); // "09"
console.log(unused([2015, 8, 26]));    // "3479"

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