Created
May 23, 2013 17:53
-
-
Save TimWolla/5638016 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
swap = -> | |
inputVar = parseInt document.getElementById('userInput').value | |
return undefined unless inputVar? | |
output.innerHTML = '' | |
inputVar *= -1 if inputVar < 0 | |
copy = inputVar | |
count = 1 | |
count++ while parseInt(copy /= 10) > 0 | |
for i in [0..count] | |
temp = parseInt inputVar / power 10, i | |
temp2 = 10 * parseInt inputVar / power 10, i + 1 | |
output.innerHTML += temp - temp2 | |
power = (base, pow) -> | |
out = 1 | |
negative = pow < 0 | |
pow *= -1 if negative | |
for i in [0..pow] | |
if negative | |
out /= base | |
else | |
out *= base | |
out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment