Skip to content
Snippets Groups Projects
Commit 69070404 authored by Thomas Fritsch's avatar Thomas Fritsch
Browse files

simplification sortByPrice

parent 0a745f7f
Branches
Tags
No related merge requests found
...@@ -108,17 +108,13 @@ function sortByName(a, b) { ...@@ -108,17 +108,13 @@ function sortByName(a, b) {
} }
return 0; return 0;
} }
// tri par prix_petit croissant PUIS par prix_grande croissant
function sortByPrice(a, b) { function sortByPrice(a, b) {
if ( a.prix_petite < b.prix_petite ) { if ( a.prix_petite !== b.prix_petite ) {
return -1; return a.prix_petite - b.prix_petite;
} 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;
} }
return 0; return a.prix_grande - b.prix_grande;
} }
// Attention : data.sort() modifie le tableau original // Attention : data.sort() modifie le tableau original
...@@ -132,7 +128,7 @@ render( data.filter( pizza => pizza.prix_petite < 6 )) ...@@ -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.split('i').length == 3 ))
render( data.filter( pizza => pizza.nom.match(/i/g).length == 2 )) 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( ({base}) => base == 'tomate' ))
render( data.filter( ({prix_petite}) => prix_petite < 6 )) render( data.filter( ({prix_petite}) => prix_petite < 6 ))
render( data.filter( ({nom}) => nom.match(/i/g).length === 2 )); render( data.filter( ({nom}) => nom.match(/i/g).length === 2 ));
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment