Last active
May 9, 2018 09:15
-
-
Save brownsmith/8b871c5c06f915ed656e9770d968822b to your computer and use it in GitHub Desktop.
Array sorting - returning products in price order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const products = [ | |
{ | |
price: '123', | |
name: 'cproduct1' | |
}, | |
{ | |
price: '50', | |
name: 'bproduct1' | |
}, | |
{ | |
price: '44', | |
name: 'aproduct1' | |
}, | |
{ | |
price: '323', | |
name: 'dproduct1' | |
} | |
] | |
function orderProducts(products) { | |
const sortedProducts = products.sort(function (a, b) { | |
return a.price - b.price; | |
}); | |
return sortedProducts.map((product, key) => { | |
return ( | |
<li key={key}>test {product.price}</li> | |
); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment