Skip to content
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

test(smokehouse): +/- operator #7343

Merged
merged 3 commits into from
Mar 1, 2019
Merged

test(smokehouse): +/- operator #7343

merged 3 commits into from
Mar 1, 2019

Conversation

connorjclark
Copy link
Collaborator

split from #7065

const NUMBER_REGEXP = /(?:\d|\.)+/.source;
const OPS_REGEXP = /<=?|>=?|\+\/-/.source;
const NUMERICAL_EXPECTATION_REGEXP =
new RegExp(`^(${NUMBER_REGEXP})?\\s?(${OPS_REGEXP})\\s?(${NUMBER_REGEXP})$`);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this clearer than ^((?:\d|\.)+)?\s?(<=?|>=?|\+\/-)\s?((?:\d|\.)+)$

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but I'm not sure I'd call either of them super clear ;)

maybe we can at least get a comment here explaining what's going on in english?

An optional number, single optional whitespace character, an operator, single optional whitespace character, a number.

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this LGTM 👍 (approval pending your thoughts on two comments)

const operator = parts[1];
const number = parseFloat(parts[2]);
const operator = parts[2];
const numbers = [parts[1], parts[3]].filter(p => typeof p !== 'undefined').map(parseFloat);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd make more sense if you nixed the filter and made it explicit

const [prefixNumber, operator, postfixNumber] = parts
// optional named descriptor, though IMO probably unnecessary and might just add cognitive overload
const targetNumber = typeof prefixNumber === 'undefined' ? postfixNumber : prefixNumber

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. relying on implicit string -> float conversion. doesn't bother me here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about the parseFloat bit for a sec 😆

maybe my "optional named descriptor" is more important to me than I realized... haha

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, it would probably have been simpler to just move off the switch statement :P

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@paulirish paulirish merged commit 5c66327 into master Mar 1, 2019
@paulirish paulirish deleted the plus-minus branch March 1, 2019 19:37
items: [
{
url: 'http://localhost:10200/byte-efficiency/script.js',
wastedBytes: '46481 +/- 100',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants