Skip to content

Commit

Permalink
Change solution challenge 12
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsi15 committed Dec 17, 2024
1 parent 0b58b23 commit caffd33
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions challenges-2024/challenge-12/calculatePrice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,5 +30,5 @@ export function calculatePrice(ornaments) {
return result
}

const result = calculatePrice('#@Z')
const result = calculatePrice('***')
console.log(result)

0 comments on commit caffd33

Please sign in to comment.