33
loading...
This website collects cookies to deliver better user experience
Functions should do one thing. They should do it well. They should do it only.
const checkForValidOrder = (order, customer) => {
let tax=15;
return
order.status==='PLACED' &&
order.payment==='SUCCESSFUL' &&
order.price(1 + (tax/100)) <= customer.walletBalance
}
const checkForValidOrder = (order, customer) => {
return
order.status==='PLACED' &&
order.payment==='SUCCESSFUL' &&
generateTotalAmount(order.price, tax) <= customer.walletBalance
}
const checkForValidOrder = (order, customer) => {
return
order.status==='PLACED' &&
order.payment==='SUCCESSFUL' &&
generateTotalAmount(order.price) <= customer.walletBalance
}
const generateTotalAmount = (price) => {
let tax=15;
return price(1 + (tax/100));
}
const describeFruit = (color, name, size, price, numSeeds, type) => {
return `${fruitName} is ${fruitColor}. It's ${fruitSize}.
It costs ${price}. It has ${numSeeds}. The type if
${type}`;
}
const describeFruit = (fruit) => {
return `${fruit.name} is ${fruit.color}. It's
${fruit.size}. It costs ${fruit.price}. It has
${fruit.numSeeds}. The type if ${fruit.type}`;
}
let numberOfBoxes = 1;
const addBoxes = () => {
numberOfBoxes++;
}
const removeBoxes = () => {
numberOfBoxes--;
}
const addBoxes = (numberOfBoxes) => numberOfBoxes + 1;
const removeBoxes = (numberOfBoxes) => numberOfBoxes - 1;
Don't repeat yourself. They are functions for a reason.