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

306
Views
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 answers
Answer question

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 Report

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 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!