Guest User

Untitled

a guest
Apr 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. function sortByPrice (validProducts) {
  2. validProducts.sort(compareValues)
  3. function convertStringToNumber (num) {
  4. return parseInt(num)
  5. }
  6. function compareValues (a, b) {
  7. const firstProductPrice = convertStringToNumber(a.product_price)
  8. const secondProductPrice = convertStringToNumber(b.product_price)
  9. if (firstProductPrice > secondProductPrice) {
  10. return -1
  11. }
  12. if (firstProductPrice < secondProductPrice) {
  13. return 1
  14. }
  15. return 0
  16. }
  17. }
Add Comment
Please, Sign In to add comment