Skip to content

Commit

Permalink
Refactor sort function
Browse files Browse the repository at this point in the history
  • Loading branch information
fanny committed May 23, 2019
1 parent 33f72e9 commit f4d3695
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
13 changes: 6 additions & 7 deletions react/components/ProductSummaryPrice/ProductSummaryPrice.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
prop,
flatten,
map,
filter
filter,
head,
last
} from 'ramda'
import classNames from 'classnames'
import { Spinner } from 'vtex.styleguide'
Expand All @@ -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,
Expand Down
11 changes: 3 additions & 8 deletions react/legacy/components/ProductSummaryPrice.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
flatten,
map,
filter,
sort,
compose,
head,
last
} from 'ramda'
Expand All @@ -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,
Expand Down

0 comments on commit f4d3695

Please sign in to comment.