Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Class October 24th

livebook/October_24.livemd

Class October 24th

Mutation

defmodule M do
  def f(x) do
    2 * x
  end
end
x = 30
M.f(x)
x
x = 1000
M.f(x)
x = M.f(x)
x
IO.puts("1200")
2300
even = Enum.to_list(10..50//2)
newList = List.replace_at(even, 2, 13)
even
defmodule Math do
  # def smallest_largest(list) do
  #   smallest = Enum.min(list)
  #   largest = Enum.max(list)
  #   {smallest, largest}
  # end

  def smallest_largest([head | tail]), do: smallest_largest(tail, head, head)
  def smallest_largest(_), do: {:error, "Input must be a non-empty list"}
  def smallest_largest([], smallest, largest), do: {smallest, largest}

  def smallest_largest([head | tail], smallest, largest) do
    new_smallest = if head < smallest, do: head, else: smallest
    new_largest = if head > largest, do: head, else: largest
    smallest_largest(tail, new_smallest, new_largest)
  end
end
list = Enum.to_list(11..5_000_001//2)
Math.smallest_largest(list)