Skip to content

Instantly share code, notes, and snippets.

@monoblaine
Forked from ssg/validate.js
Last active March 28, 2016 09:17
Show Gist options
  • Save monoblaine/1b27a3e6e8294877ef2c to your computer and use it in GitHub Desktop.
Save monoblaine/1b27a3e6e8294877ef2c to your computer and use it in GitHub Desktop.
Turkish ID Validator in a Tweet Attempt
tc=n=>{if(n=n.split('').map(Number),o=n[e=i=0],c=n[9],t=10,o)for(;++i<9;)eval((i%2?'e':'o')+'+=n[i]');return!((7*o-e+t)%t-c|(o+e+c)%t-n[t])}
@atesgoral
Copy link

Use of eval is so evil and so nice in this context :)

@atesgoral
Copy link

The t=10, replacement (taking up 5 characters) actually makes it worse by 1 character since 10 is only used 4 times (8 characters). Dropping the tc= assignment and the t=10, replacement, you're down to 136 characters:

n=>{if(n=n.split('').map(Number),o=n[e=i=0],c=n[9],t=10,o)for(;++i<9;)eval((i%2?'e':'o')+'+=n[i]');return!((7*o-e+t)%t-c|(o+e+c)%t-n[t])}

@monoblaine
Copy link
Author

Wow, seems like we may even mention someone :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment