Created
May 23, 2014 13:15
-
-
Save kumarldh/26f3feaa56068939f50c 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Given a number count trailing zeros!</title> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
This is different from counting trailing zeroes from a given factorial. | |
<script> | |
function countTrailingZeros(input){ | |
if(input === undefined || input < 10){ | |
return 0; | |
} | |
var count = 0, multipleOfTen = 10, newvalue=0; | |
for(var i = 1; multipleOfTen <= input; i++) { | |
newvalue = parseInt(input/multipleOfTen); | |
if((newvalue * multipleOfTen ) === input){ | |
multipleOfTen = multipleOfTen * 10; | |
count ++; | |
}else{ | |
break; | |
} | |
} | |
return count; | |
} | |
console.log(countTrailingZeros(1000)); | |
console.log(countTrailingZeros(1200)); | |
console.log(countTrailingZeros(1230)); | |
console.log(countTrailingZeros(1234)); | |
console.log(countTrailingZeros(4)); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment