-
Notifications
You must be signed in to change notification settings - Fork 9
Added comparison functions (GT/LT) to dice: !roll 1d20 + x > y #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
} else { | ||
text = ' Failure! ' + result + ' is higher than ' + target; | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could the quantifier be equal or not equal to? or what about GTE/LTE?
- Changed the checkTarget function to use different, cooler syntax. - Included E, GTE and LTE checks.
Updated pull request with suggestions. |
}; | ||
if (quantifiers[quantifier.toLowerCase()](parseFloat(result), parseFloat(target))) text = ' `Success!`'; | ||
return text; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8000this is getting nitpicky, there really isnt anything wrong with what you have (except for maybe the parsefloat()) but here is how I would write this function:
function checkTarget(result, quantifier, target) {
//do your argument manipulation, defaulting, etc at the top of the function
//making your use of them more clear
quantifier = quantifier.toLowerCase();
//either use lodash's parseFloat or use parseFload(result, 10)
result = _.parseFloat(result);
target = _.parseFloat(target);
let quantifiers = {
//personal style preferences
'>': (a, b) => a > b,
'<': (a, b) => a < b,
'>=': (a, b) => a >= b,
'<=': (a, b) => a <= b,
'=': (a, b) => a === b
};
//this line is much easier to read with the manipulation stuff already done
if (quantifiers[quantifier](result, target)){
//I personally only use bracket-less if statements when doing an early bail-out return,
//like when the function should just not run - errors or something like that
return ' `Success!`';
}
//no need to store the result, just return it where necessary
return ' `Failure!`'
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more info on parseInt() http://stackoverflow.com/questions/16880327/why-am-i-getting-weird-result-using-parseint-in-node-js-different-result-from
you can also use Number()
in most cases instead of parseInt
If/when this lands it will require updates to the |
critique welcome, as always.
I think checkTarget() can be streamlined, but I'm not sure how