diff --git a/js/main.js b/js/main.js index 7797e092416f5a3fada9a7b0048c6f419b35ac42..eac79b2b81c3edaded3110535c68f4cd28c3d977 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