Final Prices With a Special Discount in a Shop LeetCode solution in JavaScript

1
var finalPrices = function (prices) {
2
let adjPrices = [];
3
while (prices.length) {
4
let currentPrice = prices[0];
5

6
// Remove first price in original array
7
// Since we're looking for a price less than or equal to
8
prices.shift();
9

10
let lowerPrice = prices.find((a) => a <= currentPrice);
11
adjPrices.push(lowerPrice ? currentPrice - lowerPrice : currentPrice);
12
}
13

14
return adjPrices;
15
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0