patterns of functional programming developing an employee

PHOTO EMBED

Fri Aug 27 2021 02:29:41 GMT+0000 (Coordinated Universal Time)

Saved by @13tinydots #javascript

const withEmail = (state) => ({
  getEmail() {
    return `${state.email}`;
  },
});

const withPay = (state) => ({
  getPayCheck() {
    return (state.salary / 52).toFixed(2);
  },
  giveRaise(amount) {
    return state.salary + amount;
  },
  getSalary(state) {
    return state.salary;
  },
});

const withVaca = (state) => ({
  getVacaDays() {
    return `${state.vacaDays}`;
  },
  useVaca(days) {
    return state.vacaDays - days;
  },
});

const createEmployee = ({ name, email, salary = 99000, vacaDays = 21 }) => {
  const employee = {
    name,
    email,
    salary,
    vacaDays,
  };
  return {
    ...withEmail(employee),
    ...withPay(employee),
    ...withVaca(employee),
  };
};

const withCode = (state) => ({
  code(project) {
    return `${state.name} is coding ${project} 👩🏾‍💻 in ${state.language}`;
  },
});

const withDesign = (state) => ({
  design(project) {
    return `${state.name} is designing ${project} 💻👩🏾`;
  },
});

const createDeveloper = ({ name, email, language = "JS" }) => {
  const state = {
    language,
  };

  return {
    ...createEmployee({ name, email }),
    ...withCode(state),
  };
};

const createDesignerDeveloper 

return {
  ...createEmployee({ name, email }),
  ...createDeveloper
  ...withDesign()
}

const newEmp = createEmployee({ name: "Blanche", email: "blanche@gmail.com" });
const dev = createDeveloper({ name: "JS Dev", email: "coder@gam.com" });

// console.log(newEmp.getEmail(), newEmp.getPayCheck(), newEmp.giveRaise(1000));
console.log(dev);
content_copyCOPY