Skip to content

Instantly share code, notes, and snippets.

@GeDiez
Last active March 21, 2018 00:59
Show Gist options
  • Save GeDiez/c22a5fef2d0750d391cbc6efe530dc15 to your computer and use it in GitHub Desktop.
Save GeDiez/c22a5fef2d0750d391cbc6efe530dc15 to your computer and use it in GitHub Desktop.
Ejemplo crear objetos: puras funciones
const calculateIMC = (height, weight) => {
const imc = this.weight / Math.pow(this.height, 2).toFixed(2);
if(imc < 16){
return 'delgadez severa imc ' + imc;
}
if(imc < 16.99){
return 'delgadez moderada imc ' + imc;
}
if(imc < 18.49){
return 'delgadez aceptable imc ' + imc;
}
if(imc < 24.99){
return 'peso normal imc ' + imc;
}
if(imc < 29.99){
return 'sobrepeso imc ' + imc;
}
if(imc < 34.99){
return 'Obeso tipo 1 imc ' + imc;
}
if(imc < 40){
return 'Obeso Tipo 2 imc ' + imc;
}
return 'Obeso Tipo 3' + imc;
};
const createPerson = ({name, secondName, lastName, age, height, weight}) => {
const getFullName = () => `${name} ${secondName} ${lastName}`;
return {
name,
age,
height,
weight,
getIMC: calculateIMC(height, weight),
getFullName,
}
}
const juan = createPerson(
{
name: 'Letsis',
secondName: 'Yamaz',
lastName: 'Navarro',
age: 20,
height: 1.70,
weight: 80
}
);
juan.getFullName(); //=> 'juan'
juan.getIMC; //=> 28.23345453
const calculateMonthlySalary = salary => salary * 30;
const Worker = ({person, salary}) => ({
...person,
salary,
monthlySalary: calculateMonthlySalary(salary),
});
const workerJuan = Worker({person: juan, salary: 100});
workerJuan.monthlySalary; // => 3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment