From 69070404f95a97b09bcb7c9e8f87b60b91481506 Mon Sep 17 00:00:00 2001
From: Thomas Fritsch <tf@kumquats.fr>
Date: Fri, 7 Feb 2020 15:26:01 +0100
Subject: [PATCH] simplification sortByPrice

---
 js/main.js | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/js/main.js b/js/main.js
index 7797e09..eac79b2 100644
--- a/js/main.js
+++ b/js/main.js
@@ -108,17 +108,13 @@ function sortByName(a, b) {
 	}
 	return 0;
 }
+
+// tri par prix_petit croissant PUIS par prix_grande croissant
 function sortByPrice(a, b) {
-	if ( a.prix_petite < b.prix_petite ) {
-		return -1;
-	} else if ( a.prix_petite > b.prix_petite ) {
-		return 1;
-	} else if ( a.prix_grande < b.prix_grande ) {
-		return -1;
-	} else if ( a.prix_grande > b.prix_grande ) {
-		return 1;
+	if ( a.prix_petite !== b.prix_petite ) {
+		return a.prix_petite - b.prix_petite;
 	}
-	return 0;
+	return a.prix_grande - b.prix_grande;
 }
 
 // Attention : data.sort() modifie le tableau original
@@ -132,7 +128,7 @@ render( data.filter( pizza => pizza.prix_petite < 6 ))
 render( data.filter( pizza => pizza.nom.split('i').length == 3 ))
 render( data.filter( pizza => pizza.nom.match(/i/g).length == 2 ))
 
-// G.3. Destructuring
+// // G.3. Destructuring
 render( data.filter( ({base}) => base == 'tomate' ))
 render( data.filter( ({prix_petite}) => prix_petite < 6 ))
 render( data.filter( ({nom}) => nom.match(/i/g).length === 2 ));
\ No newline at end of file
-- 
GitLab