Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 1.25 KB

modules_and_functions.md

File metadata and controls

25 lines (20 loc) · 1.25 KB

Exercise 1

  • Write a function in a module that takes a map with :name and prints out the value with a "-NG" appended to it since it's the NextGeneration ;) -- Ensure it takes only maps that contain the :droid atom which is true

  • Write another function (with the same name) with the (almost) same arguments that takes any name and returns it if the :droid value is false

  • Answer

Exercise 2

  • Write an & function using &1.... and sums 4 values
  • Answer

Exercise 3

  • Write an function called greeter that returns a function that takes differing types and values and prints out a different response to each. Try a map, a three element tuple, an :atom and a string. It should also take a fallthrough default value that returns :ok
  • Answer

Exercise 4

  • read up on Enum.reduce. Inside of iex How can you combine Enum.map and Enum.reduce to take a list of numbers, double each of them and then sum them up. Try the numbers 1,2,3,4 - that way you'll know the answer (20) and if you got it correct
  • Answer