From caffd33710ee548cb04e07ad23659141f2d0f30b Mon Sep 17 00:00:00 2001 From: John Serrano Date: Tue, 17 Dec 2024 17:46:07 -0500 Subject: [PATCH] Change solution challenge 12 --- challenges-2024/challenge-12/calculatePrice.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/challenges-2024/challenge-12/calculatePrice.js b/challenges-2024/challenge-12/calculatePrice.js index 2fb699c..588fe67 100644 --- a/challenges-2024/challenge-12/calculatePrice.js +++ b/challenges-2024/challenge-12/calculatePrice.js @@ -11,13 +11,16 @@ export function calculatePrice(ornaments) { for (let i = 0; i < ornaments.length; i++) { const ornament = ornaments[i] - if (prices[ornament] === undefined) return undefined + const currentPrice = prices[ornament] + + if (currentPrice === undefined) return undefined const prevOrnament = ornaments[i - 1] - const currentPrice = prices[ornament] const prevPrice = prices[prevOrnament] - if (prevOrnament && prices[ornament] > prices[prevOrnament]) { + console.log({ prevPrice, prevOrnament, currentPrice }) + + if (currentPrice > prevPrice) { result += currentPrice - 2 * prevPrice } else { result += currentPrice @@ -27,5 +30,5 @@ export function calculatePrice(ornaments) { return result } -const result = calculatePrice('#@Z') +const result = calculatePrice('***') console.log(result)