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

Good opportunity to factor out code for better legibility #6

Open
cchauche opened this issue Jul 7, 2021 · 0 comments
Open

Good opportunity to factor out code for better legibility #6

cchauche opened this issue Jul 7, 2021 · 0 comments

Comments

@cchauche
Copy link

cchauche commented Jul 7, 2021

styles = styles.map((style) => {
if (style.sale_price === 'null') {
style.sale_price = '0';
}
style['default?'] === 0
? (style['default?'] = true)
: (style['default?'] = false);
let obj = {};
for (let i = 0; i < style['skus'].length; i++) {
let sku = style['skus'][i];
obj[sku['id']] = {
quantity: sku['quantity'],
size: sku['size'],
};
}
style['skus'] = obj;
return style;

As someone unfamiliar with what your code is doing it takes a lot of work to understand what this code is doing. This is a great opportunity to factor out this logic to a function with a descriptive name. Something like formatStyles() or something like that.

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

No branches or pull requests

1 participant