Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andriikot/js-lesson-5-0
JS Lesson 5.0
https://github.com/andriikot/js-lesson-5-0
Last synced: about 2 months ago
JSON representation
JS Lesson 5.0
- Host: GitHub
- URL: https://github.com/andriikot/js-lesson-5-0
- Owner: AndriiKot
- Created: 2023-03-29T06:40:48.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-03-29T07:16:19.000Z (over 1 year ago)
- Last Synced: 2024-01-09T00:29:51.703Z (12 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JS-lesson-5-0
JS Lesson 5.0```node
const calculateSubtotal = (goods) => {
let amount = 0;// Variation 1
for (const item of goods) {
if(item.price < 0) throw 'Negative price';
else amount += item.price;
}
return amount;
};// Variation 2.0
if (item.price < 0) throw 'Negative price';
amount += item.price;if (item.price < 0) {
throw 'Negative price';
}
amount += item.price;// Variation 2.1
if(item.price < 0) return;
amount += item.price;if (item.price < 0) {
return;
}
amount += item.price;// TER.
amount += item.price < 0 ? 0 : item.price;
amount += item.price > 0 ? item.price : 0;// BAD
if (item.price > 0) return true; // !!! bad
return false; // !!! bad// Good
return item.price > 0;// BAD
if (order[groupName] && order[groupName].length > 0) { // bad
total += calculateTotal(order[groupName]);
count += order[groupName].length;
}
// Good
if (goods && goods.length > 0) {
total += calculateTotal(goods);
count += goods.lenght; // ??
}
// Very good
const goods = order[groupName];
if (goods) {
const len = goods.lenght;
if (len > 0) {
total += calculateTotal(goods);
count += len;
}
}
// Very good
const goods = order[groupName];
if (!goods) return;
const len = goods.length;
if (len > 0) {
total += calculateTotal(goods);
count += len;
}```