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

135
Views
How to return a string with quotes on output

I wrote this code:

function unusedDigits(numbers) {
    let s = numbers.join('');
    let arr = s.split('');
    let ch = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
    let arraRes = [];


    for (let i = 0; i < ch.length; i++){
        if (!arr.includes(ch[i])) {
           arraRes += ch[i];
        }
    }

    return String(arraRes); // also tried return arraRes + "";
}

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

But I can't understand why a number on output. I need on output numbers with quotes - "09" and "3479"

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The following line:

arraRes += ch[i];

Converts the array into a string. You should use push() to add stuff to an array. This way the array is preserved and you're getting an array of string as return


function unusedDigits(numbers) {
    let s = numbers.join('');
    let arr = s.split('');
    let ch = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
    let arraRes = [];


    for (let i = 0; i < ch.length; i++){
        if (!arr.includes(ch[i])) {
           arraRes.push(ch[i]);
        }
    }

    return arraRes;
}

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

about 4 years ago · Juan Pablo Isaza Report

0

Two possible ways:

Example with string simple concat

function unusedDigits(numbers) {
    let s = numbers.join('');
    let arr = s.split('');
    let ch = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];    
    let strRes= '';

    for (let i = 0; i < ch.length; i++){
        if (!arr.includes(ch[i])) {           
           strRes += ch[i] + ', ';
        }
    }
        return strRes;    
}

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

Example with array

function unusedDigits(numbers) {
    let s = numbers.join('');
    let arr = s.split('');
    let ch = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
    let arraRes = [];

    for (let i = 0; i < ch.length; i++){
        if (!arr.includes(ch[i])) {
           arraRes.push(ch[i]);
        }
    }

    return String(arraRes); // also tried return arraRes + "";
}

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

Conclusion: I would prefer the first one because you dont need to cast the array back to an string.

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!