Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to replace all ‘0’ int a number with specific digit in JavaScript

1 Answer

0 votes
function convert_0_To_n__(number, d) { 
    if (number === 0) 
        return 0; 
   
    var digit = number % 10; 
    if (digit === 0) 
        digit = d; 
   
    return convert_0_To_n__(Math.trunc(number / 10), d) * 10 + digit; 
} 
function convert_0_To_n(number, d) { 
    if (number === 0) 
        return d; 
    else
        return convert_0_To_n__(number, d); 
} 
 
var number = 1080030; 
     
document.write(convert_0_To_n(number, 7));



/*
run:

1787737 

*/

 



answered Apr 20, 2019 by avibootz

Related questions

1 answer 155 views
1 answer 161 views
1 answer 122 views
1 answer 185 views
1 answer 129 views
1 answer 148 views
...