Skip to content

Instantly share code, notes, and snippets.

@brownsmith
Last active May 9, 2018
Embed
What would you like to do?
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