Final Prices With a Special Discount in a Shop LeetCode solution in JavaScript
1var finalPrices = function (prices) {2let adjPrices = [];3while (prices.length) {4let currentPrice = prices[0];56// Remove first price in original array7// Since we're looking for a price less than or equal to8prices.shift();910let lowerPrice = prices.find((a) => a <= currentPrice);11adjPrices.push(lowerPrice ? currentPrice - lowerPrice : currentPrice);12}1314return adjPrices;15};