Skip to content

Instantly share code, notes, and snippets.

@TimWolla
Created May 23, 2013 17:53
Show Gist options
  • Save TimWolla/5638016 to your computer and use it in GitHub Desktop.
Save TimWolla/5638016 to your computer and use it in GitHub Desktop.
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