Skip to content

Instantly share code, notes, and snippets.

@tarunranka
Created December 11, 2020 06:06
Show Gist options
  • Save tarunranka/c4a475858697b3a6a3c2eb08722d2184 to your computer and use it in GitHub Desktop.
Save tarunranka/c4a475858697b3a6a3c2eb08722d2184 to your computer and use it in GitHub Desktop.
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