Skip to content

Instantly share code, notes, and snippets.

@st98
Created January 27, 2015 20:05
Show Gist options
  • Save st98/3f0725ad0f608c926e34 to your computer and use it in GitHub Desktop.
Save st98/3f0725ad0f608c926e34 to your computer and use it in GitHub Desktop.
8 進数。p('1234') === 668。
p = (s) ->
m = s.match /[0-7]+/
if m is null
return NaN
r = 0
for c, i in (m[0].split '').reverse()
n = parseInt c, 10
r += n * Math.pow 8, i
if s[0] is '-' then -r else r
t = (s) ->
Object.is (p s), (parseInt s, 8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment