diff --git a/README.md b/README.md index 3520d2d..804a5e2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Simple diagrams and resources to help learning Elixir, Phoenix, Ecto and other u - [10 tips for new elixir developpers](#10-tips-for-new-elixir-developpers) - [Elixir cheat sheet](#elixir-cheat-sheet) - [Elixir learning path](#elixir-learning-path) - - [Level 1 (Elixir)](#level-1-elixir) + - [Section 1 (Elixir)](#section-1-elixir) - [Installing Elixir and Running IEx](#installing-elixir-and-running-iex) - [Elixir guide styles (non exhaustive)](#elixir-guide-styles-non-exhaustive) - [Basics (Getting started with Elixir)](#basics-getting-started-with-elixir) @@ -24,7 +24,9 @@ Simple diagrams and resources to help learning Elixir, Phoenix, Ecto and other u - [Controls Structures (cond, with, case, if)](#controls-structures-cond-with-case-if) - [IO and files](#io-and-files) - [Debugging with Elixir](#debugging-with-elixir) - - [Level 2 (Phoenix, Ecto and OTP basics)](#level-2-phoenix-ecto-and-otp-basics) +- [👣 Get your feet wet](#-get-your-feet-wet) + - [Section 1 exercises](#section-1-exercises) + - [Section 2 (Phoenix, Ecto and OTP basics)](#section-2-phoenix-ecto-and-otp-basics) - [Mix](#mix) - [Errors and Exceptions](#errors-and-exceptions) - [Testing your code](#testing-your-code) @@ -33,7 +35,7 @@ Simple diagrams and resources to help learning Elixir, Phoenix, Ecto and other u - [OTP Basics](#otp-basics) - [Phoenix](#phoenix) - [Ecto](#ecto) - - [Level 3 (OTP, MetaProgramming)](#level-3-otp-metaprogramming) + - [Section 3 (OTP, MetaProgramming)](#section-3-otp-metaprogramming) - [Processes (Spawn, Links, Tasks, etc.)](#processes-spawn-links-tasks-etc) - [Supervisors](#supervisors) - [AST](#ast) @@ -95,7 +97,7 @@ Anyone can contribute, add resources, links and update mermaid diagrams :) Feel # Elixir learning path -## Level 1 (Elixir) +## Section 1 (Elixir) → At this level, you can practice coding with Elixir using the [Exercism’s Elixir track](https://exercism.org/tracks/elixir), a website where you can find puzzles and exercises for every Elixir concepts. Plus, their [Sylabus](https://exercism.org/tracks/elixir/concepts) is great! @@ -211,7 +213,16 @@ Doc[Documentation and Typespecs] - [Three Ways to Debug Code in Elixir by Pulkit Goyal](https://blog.appsignal.com/2021/11/30/three-ways-to-debug-code-in-elixir.html) -## Level 2 (Phoenix, Ecto and OTP basics) +# 👣 Get your feet wet + +After reading through all these documentations for the first section, you must have gathered some basic knowledge about Elixir. +Now, let's do a series of exercises covering different concepts we mentioned above, and get yourself more familiar with the language. +The exercises were written in Livebook. + +### Section 1 exercises +[![Run in Livebook](https://livebook.dev/badge/v1/black.svg)](https://livebook.dev/run?url=https%3A%2F%2Felixir-learning-path.fly.dev%2Fsessions%2Fxgcbllf6pzsuj7nyhv2qdjock36exfvtv4qydeav) + +## Section 2 (Phoenix, Ecto and OTP basics) ```mermaid graph TD @@ -313,7 +324,7 @@ graph TD - [Ecto.Multi hexdoc](https://hexdocs.pm/ecto/Ecto.Multi.html) - [Dynamic queries](https://hexdocs.pm/ecto/dynamic-queries.html) -## Level 3 (OTP, MetaProgramming) +## Section 3 (OTP, MetaProgramming) ```mermaid graph TD diff --git a/exercises/section_1.livemd b/exercises/section_1.livemd new file mode 100644 index 0000000..b47363a --- /dev/null +++ b/exercises/section_1.livemd @@ -0,0 +1,80 @@ +# Elixir Learning Path + +## Section 1 exercises + +Get your hands dirty on Elixir with the series of exercises below. The idea is to write a function that returns expected output, with unit tests implemented. + + + +### String length + +Given a string, you need to return the number of characters. + +```elixir +defmodule String.Length do + def string_length(string) do + ## Your solution here + end +end +``` + +```elixir +ExUnit.start(auto_run: false) + +defmodule String.LengthTest do + use ExUnit.Case, async: false + alias String.Length + + describe "string_length/1" do + test "the length of hello is 5" do + assert Length.string_length("hello") == 5 + end + + test "the length of wikipedia is 9" do + assert Length.string_length("wikipedia") == 9 + end + + test "the length of dsqsqdqsdeqdfqfaezaezeqsdsqrerdsqdqsdqdqdqs is 43" do + assert Length.string_length("dsqsqdqsdeqdfqfaezaezeqsdsqrerdsqdqsdqdqdqs") == 43 + end + end +end + +ExUnit.run() +``` + +### Addition + +Write a function that returns the addition of a and b. + +```elixir +defmodule Addition do + def add(a, b) when is_integer(a) and is_integer(b) do + ## Your solution here + end +end +``` + +```elixir +ExUnit.start(auto_run: false) + +defmodule AdditionTest do + use ExUnit.Case, async: false + + describe "add/2" do + test "2 add 1 equals 3" do + assert Addition.add(2, 1) == 3 + end + + test "532323132 add 2423242424 equals" do + assert Addition.add(532_323_132, 2_423_242_424) == 2_955_565_556 + end + + test "if one of the element is not integer should transform it and perform addition" do + assert Addition.add("2", 1) == 3 + end + end +end + +ExUnit.run() +```