Created
December 11, 2020 06:06
-
-
Save tarunranka/c4a475858697b3a6a3c2eb08722d2184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function replace0by5(number){ | |
if(number === 0){ | |
return 5; | |
} | |
var result=number,decimalPlace=1; | |
while(number > 0){ | |
if(number % 10 === 0){ | |
var newNumber = 5*decimalPlace; | |
result += newNumber; | |
} | |
number = Math.floor(number/10); | |
decimalPlace *=10; | |
} | |
return result; | |
} | |
console.log(replace0by5(10500)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment