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

function lowest_price() {
  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;
}

function main() {
  return lowest_price();
}