Skip to content

Instantly share code, notes, and snippets.

@abiodun0
Created September 24, 2016 00:02
Show Gist options
  • Save abiodun0/b3cc301b4f3cffb2e0464b785f4b2afe to your computer and use it in GitHub Desktop.
Save abiodun0/b3cc301b4f3cffb2e0464b785f4b2afe to your computer and use it in GitHub Desktop.
function pay() {
for(var i = 0; i< employees.length; i++ ){
if(employees[i].isPayDay()){
let pay = employees[i].calculate(pay);
employees[i].deliverPay(pay);
}
}
}
// This particular piece of code does three things.. Refactoring
function pay() {
for(var i = 0; i< employees.length; i++ ){
payIfNeccessary(employees[i]);
}
}
function payIfNecessary(employee) {
if (employee.isPayday()) calculateAndDeliverPay(employee);
}
function calculateAndDeliverPay(employee) {
pay = employee.calculatePay();
employee.deliverPay(pay);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment