@bluelilo/search-utils
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -18,17 +18,56 @@ "use strict"; | ||
function sortPriceHighLow(results) { | ||
const sortedResults = results.slice(0).sort((a, b) => { | ||
const minA = Math.min(...boardOptionsToTotals(a.boardOptions)); | ||
const minB = Math.min(...boardOptionsToTotals(b.boardOptions)); | ||
return minB - minA; | ||
}); | ||
return sortBoardOptions(sortedResults); | ||
} | ||
function sortPriceLowHigh(results) { | ||
const sortedResults = results.slice(0).sort((a, b) => { | ||
const minA = Math.min(...boardOptionsToTotals(a.boardOptions)); | ||
const minB = Math.min(...boardOptionsToTotals(b.boardOptions)); | ||
return minA - minB; | ||
}); | ||
return sortBoardOptions(sortedResults); | ||
} | ||
function sortRecommended(results) { | ||
const sortedResults = sortPriceLowHigh(results); | ||
const providerResults = Object.values(sortedResults.reduce((providers, result) => { | ||
if (!providers[result.provider]) providers[result.provider] = []; | ||
providers[result.provider].push(result); | ||
return providers; | ||
}, {})); | ||
const zippedResults = []; | ||
let hasResult = true; | ||
while (hasResult) { | ||
hasResult = false; | ||
for (const providerResult of providerResults) { | ||
const result = providerResult.shift(); | ||
if (result) { | ||
zippedResults.push(result); | ||
} | ||
if (providerResult.length > 0) { | ||
hasResult = true; | ||
} | ||
} | ||
} | ||
return zippedResults; | ||
} | ||
function sort(results, sortBy) { | ||
if (sortBy === 'PRICE_HIGH_LOW') { | ||
const sortedResults = results.slice(0).sort((a, b) => { | ||
const minA = Math.min(...boardOptionsToTotals(a.boardOptions)); | ||
const minB = Math.min(...boardOptionsToTotals(b.boardOptions)); | ||
return minB - minA; | ||
}); | ||
return sortBoardOptions(sortedResults); | ||
return sortPriceHighLow(results); | ||
} else if (sortBy === 'PRICE_LOW_HIGH') { | ||
const sortedResults = results.slice(0).sort((a, b) => { | ||
const minA = Math.min(...boardOptionsToTotals(a.boardOptions)); | ||
const minB = Math.min(...boardOptionsToTotals(b.boardOptions)); | ||
return minA - minB; | ||
}); | ||
return sortBoardOptions(sortedResults); | ||
return sortPriceLowHigh(results); | ||
} else if (sortBy === 'RECOMMENDED') { | ||
return sortRecommended(results); | ||
} | ||
@@ -35,0 +74,0 @@ |
{ | ||
"name": "@bluelilo/search-utils", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10850
316