// Wrong
const groupedOrders = _.groupBy(orders, (orderItem) => orderItem.transaction_id);
const result = _.map(groupedOrders, (groupedOrders) => doSomething(groupedOrders));
// Correct
_.chain(orders)
.groupBy((orderItem) => orderItem.transaction_id)
.map((groupedOrders) => doSomething(groupedOrders))
.value();
Use utility methods that conveys your logic rather than writing the logic imperatively.
const names = ['a', 'b', 'c'];
const ids = [1, 2, 3];
// Wrong
_.map(names, (name, index) => {
const id = ids[index];
...
});
// Correct
_.map(_.zip(names, ids), [name, id] => {
...
});
// Wrong:
const superCategory = "fire"
const superCategoryObject = _.find(CONFIG.***, ***)
// Correct:
const superCategoryName = "fire"
const superCategoryConfig = _.find(CONFIG.***, ***)
// Wrong:
const inputEmail = '[email protected]'
_.map(allowedEmails, (email) => { *** });
// Correct
const inputEmail = '[email protected]'
_.map(allowedEmails, (allowedEmail) => { *** });
// Wrong
temp = get_house_price_in_usd(house_sqft, house_room_count)
final_value = temp * usd_to_aud_conversion_rate
// Correct
house_price_in_usd = get_house_price_in_usd(house_sqft, house_room_count)
house_price_in_aud = house_price_in_usd * usd_to_aud_conversion_rate
// Wrong
temp = m1 * x1 + m2 * (x2 ** 2)
final = temp + b
// Correct
house_price = price_per_room * rooms + price_per_floor_squared * (floors ** 2)
house_price = house_price + expected_mean_house_price
// Wrong
if (isDisabled) { ....
if (!isDisabled) { ...
// Correct
if(isEnabled) { ....
if(!isEnabled) { ....
// Wrong
const parser = {
parseProductCode: () => { ... },
parseQuantity: () => { ... },
tradingSymbolParse: () => { ... },
}
// Correct
const parser = {
parseProductCode: () => { ... },
parseQuantity: () => { ... },
parseTradingSymbol: () => { ... },
}
// Wrong
const fn = () => {
if (isValid()) {
if (isSafe()) {
return doWork();
} else {
return []
}
} else {
throw new Error('Not Valid');
}
}
// Correct
const fn = () => {
if (!isValid()) {
throw new Error('Not Valid');
}
if (!isSafe()) {
return [];
}
return doWork();
}