From f4d369568f8227e26d3dbd1589fb5504d82d5b1b Mon Sep 17 00:00:00 2001 From: Fanny Date: Thu, 23 May 2019 10:16:30 -0300 Subject: [PATCH] Refactor sort function --- .../ProductSummaryPrice/ProductSummaryPrice.js | 13 ++++++------- react/legacy/components/ProductSummaryPrice.js | 11 +++-------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/react/components/ProductSummaryPrice/ProductSummaryPrice.js b/react/components/ProductSummaryPrice/ProductSummaryPrice.js index 56b45faf..becc49bb 100644 --- a/react/components/ProductSummaryPrice/ProductSummaryPrice.js +++ b/react/components/ProductSummaryPrice/ProductSummaryPrice.js @@ -5,7 +5,9 @@ import { prop, flatten, map, - filter + filter, + head, + last } from 'ramda' import classNames from 'classnames' import { Spinner } from 'vtex.styleguide' @@ -15,14 +17,11 @@ import ProductSummaryContext from '../ProductSummaryContext' import { productShape } from '../../utils/propTypes' import productSummary from '../../productSummary.css' -const sortPrices = (priceA, priceB) => priceA - priceB -const lowestPrice = compose(head, sort(sortPrices)) -const highestPrice = compose(last, sort(sortPrices)) - const isAvailableProduct = price => price !== 0 const getListPrices = prices => { - const lowPrice = lowestPrice(prices) - const highPrice = highestPrice(prices) + const sortPrices = prices.sort() + const lowPrice = head(sortPrices) + const highPrice = last(sortPrices) return [ lowPrice, highPrice, diff --git a/react/legacy/components/ProductSummaryPrice.js b/react/legacy/components/ProductSummaryPrice.js index 88e1d7ed..c77f4871 100644 --- a/react/legacy/components/ProductSummaryPrice.js +++ b/react/legacy/components/ProductSummaryPrice.js @@ -6,8 +6,6 @@ import { flatten, map, filter, - sort, - compose, head, last } from 'ramda' @@ -16,14 +14,11 @@ import { ProductPrice } from 'vtex.store-components' import { productShape } from '../../utils/propTypes' -const sortPrices = (priceA, priceB) => priceA - priceB -const lowestPrice = compose(head, sort(sortPrices)) -const highestPrice = compose(last, sort(sortPrices)) - const isAvailableProduct = price => price !== 0 const getListPrices = prices => { - const lowPrice = lowestPrice(prices) - const highPrice = highestPrice(prices) + const sortPrices = prices.sort() + const lowPrice = head(sortPrices) + const highPrice = last(sortPrices) return [ lowPrice, highPrice,