You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

0 D铆as
21 Hrs
52 Min
10 Seg

Principio DRY

22/24
Resources

Contributions 8

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

toma 馃, si llegaste hasta aqu铆 te mereces un aguacate.

Principio DRY: Don鈥檛 repeat yourself (No te repitas a ti mismo).

No repetir c贸digo, sino extraerlo a una clase o funci贸n para poder reutilizarlo.

// Obtener un promedio
// Ejemplo de c贸digo que se repite
const juanAverage = (90 + 50 + 70) / 3;
const alexAverage = (80 + 90 + 70 + 80) / 4;
const candeAverage = (40 + 100) / 2;

console.log(juanAverage, alexAverage, candeAverage);

// Soluci贸n del c贸digo anterior para ser reutilizado
function getAverage(...grades) {
	return grades.reduce((prev, current) => prev + current, 0) / grades.length;
}

const juanAverage2 = getAverage(90 + 50 + 70);
const alexAverage2 = getAverage(80 + 90 + 70 + 80);
const candeAverage2 = getAverage(40 + 100);

console.log(juanAverage2, alexAverage2, candeAverage2);

ME ENCANTO ESTE CURSO, me puse arrevisar mi codigo, y valla que cantidad de errores cometia

Buen concepto
![](https://static.platzi.com/media/user_upload/image-2b1f7403-3ab5-4c0d-b523-0a15f095d655.jpg)
![](https://static.platzi.com/media/user_upload/image-3a29a736-3d73-4570-90c6-840f2b5f71ba.jpg)

Para entender mejor el metodo reduce, les recomiendo esta clase:
https://platzi.com/clases/2461-arrays/40876-reduce/

Espero que mi aporte les ayude 馃槂
Dry aplicado a una soluci贸n que convierte los Fahrenheit a Celsius.