summaryrefslogtreecommitdiff
path: root/demo/script.js
blob: 5f536fd4156df68fc893550bd96b75b647421b46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

function main() {
  const offers = [{ id: 1, price: 2.01}, { id: 2, price: 2.99 }];

  let min_price = null;
  let best_offer = null;

  for (const offer of offers) {
    if (min_price === null || offer.price < min_price) {
      min_price = offer.price;
      best_offer = offer;
    }
  }

  return best_offer;
}