Skip to content

Instantly share code, notes, and snippets.

@TechWithTy
Created September 10, 2019 23:22
Show Gist options
  • Save TechWithTy/ad31723fd74a50a08cd103cc210bb48d to your computer and use it in GitHub Desktop.
Save TechWithTy/ad31723fd74a50a08cd103cc210bb48d to your computer and use it in GitHub Desktop.
Sorting Algorithm One Liners
// console.log(
// tempProducts.sort((a, b) => parseFloat(a.price) - parseFloat(b.price)),
// 'Price Lowest to Highest'
// );
// console.log(
// tempProducts.sort((a, b) => parseFloat(b.price) - parseFloat(a.price)),
// 'Price Highest to Lowest'
// );
// console.log(
// tempProducts.sort((a, b) => parseFloat(b.avgReview) - parseFloat(a.avgReview) ),
//
// ); Best Selling By Review
//Sort By Oldest
// console.log(
// tempProducts.sort((a, b) => new Date(a.uploadDate) - new Date(b.uploadDate)));
// Newest To Oldest
// Sort By Latest
console.log(
tempProducts.sort((a, b) => new Date(b.uploadDate) - new Date(a.uploadDate) ));
// Sort by Featured Bool
// console.log(tempProducts.sort((a, b) => b.isFeatured - a.isFeatured ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment