Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sortByPrice (validProducts) {
- validProducts.sort(compareValues)
- function convertStringToNumber (num) {
- return parseInt(num)
- }
- function compareValues (a, b) {
- const firstProductPrice = convertStringToNumber(a.product_price)
- const secondProductPrice = convertStringToNumber(b.product_price)
- if (firstProductPrice > secondProductPrice) {
- return -1
- }
- if (firstProductPrice < secondProductPrice) {
- return 1
- }
- return 0
- }
- }
Add Comment
Please, Sign In to add comment