Skip to content

Instantly share code, notes, and snippets.

@brownsmith
Last active May 9, 2018 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brownsmith/8b871c5c06f915ed656e9770d968822b to your computer and use it in GitHub Desktop.
Save brownsmith/8b871c5c06f915ed656e9770d968822b to your computer and use it in GitHub Desktop.
Array sorting - returning products in price order
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