Last active
January 3, 2016 20:38
-
-
Save gnab/8515838 to your computer and use it in GitHub Desktop.
Sweet.js random expression macro
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
macro random { | |
case { _ ($expr:expr (,) ...) } => { | |
var matches = match.patternEnv.$expr.match; | |
var randomIndex = Math.floor(Math.random() * matches.length); | |
var randomMatch = matches[randomIndex].match; | |
return randomMatch | |
} | |
} | |
random(console.log(1), console.log(2), console.log(3)) | |
// => console.log(1) OR console.log(2) OR console.log(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment