Created
April 2, 2011 10:08
-
-
Save gdotdesign/899368 to your computer and use it in GitHub Desktop.
Parses a string as a mathematical expression. Replaces percentages based on a number.
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
Number.eval("200%-140%-700",1280) | |
// result 68 |
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
Number.eval = (string,size) -> | |
Number.from(eval(String.from(string).replace /(\d*)\%/g, (match,str) -> | |
(Number.from(str)/100)*size | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment