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

simplification sortByPrice

parent 0a745f7f
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment