function maxProfit(prices) {
// end::description[]
// tag::solution[]
  let max = 0;
  let local = Infinity;
  for (let i = 0; i < prices.length; i++) {
    local = Math.min(local, prices[i]);
    max = Math.max(max, prices[i] - local);
  }
  return max;
}
Find the max profit from buying and selling a stock given their daily prices.
@examples
   maxProfit([5, 10, 5, 10]); // => 5
   maxProfit([1, 2, 3]); // => 2
   maxProfit([3, 2, 1]); // => 0
@param {number[]} prices - Array with daily stock prices
@returns {number} - Max profit