This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "war" |> String.upcase |> String.split("") |> Enum.reverse |> Enum.join("") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Enum.join(Enum.reverse(String.split(String.upcase("war"), "")), "") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # is it assignment? | |
| all_systems = :go | |
| # not quite | |
| :go = all_systems | |
| # alas age is but a number | |
| tom = %{name: "Tom", age: 25} | |
| %{age: num} = tom # 25 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const hey = (person) => { | |
| person.name = person.name || "Tom"; | |
| console.log(`Hey, ${person.name}`); | |
| }; | |
| let bob = {}; | |
| hey(bob); // "Hey, Tom" | |
| bob // { name: "Tom" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Greeting do | |
| def hey(name) do | |
| name = name || "Tom" | |
| IO.puts "Hey, " <> name | |
| end | |
| end | |
| test_name = nil | |
| Greeting.hey(test_name) # Hello, Tom | |
| test_name # nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Arrow functions with one parameter | |
| [1, 2, 3].map(x => x * x); // [1, 4, 9] | |
| // Arrow functions with multiple parameters | |
| [1, 2, 3].reduce((x, s) => s + x); // 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Lambdas with one parameter | |
| [1, 2, 3] |> Enum.map(&(&1 * &1)) # [1, 4, 9] | |
| # Lambdas with multiple parameters | |
| [1, 2, 3] |> Enum.reduce(&(&1 + &2)) # 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Fib do | |
| def fibonacci(0), do: 1 | |
| def fibonacci(1), do: 1 | |
| def fibonacci(n) when n > 1 do | |
| fibonacci(n-1) + fibonacci(n - 2) | |
| end | |
| def fibonacci(_), do: nil | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fibonacci = (n) => { | |
| if (n < 0) { | |
| return null; | |
| } else if (n == 0 || n == 1) { | |
| return 1; | |
| } else { | |
| return fibonacci(n - 1) + fibonacci(n - 2); | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Greet do | |
| def hey(name) when is_atom(name) do | |
| name |> to_string |> hey | |
| end | |
| def hey(name) when is_binary(name) do | |
| IO.puts "Hello, " <> name | |
| end | |
| end |