• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jaeyson / freecodecamp_elixir / 2cc9dcc7fa8586528952c9ca8b488ffc49a3bd07

29 Jul 2024 09:42AM UTC coverage: 100.0%. Remained the same
2cc9dcc7fa8586528952c9ca8b488ffc49a3bd07

Pull #87

github

web-flow
Bump excoveralls from 0.18.1 to 0.18.2

Bumps [excoveralls](https://github.com/parroty/excoveralls) from 0.18.1 to 0.18.2.
- [Release notes](https://github.com/parroty/excoveralls/releases)
- [Changelog](https://github.com/parroty/excoveralls/blob/master/CHANGELOG.md)
- [Commits](https://github.com/parroty/excoveralls/compare/v0.18.1...v0.18.2)

---
updated-dependencies:
- dependency-name: excoveralls
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #87: Bump excoveralls from 0.18.1 to 0.18.2

87 of 87 relevant lines covered (100.0%)

2128.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/lib/freecodecamp_elixir/intermediate_algo.ex
1
defmodule FreecodecampElixir.IntermediateAlgo do
2
  @moduledoc """
3
  Documentation for Freecodecamp ([Intermediate Alogrithmic Scripting](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/#intermediate-algorithm-scripting)).
4
  """
5
  @moduledoc since: "0.1.0"
6

7
  @doc """
8
  We'll pass you an array of two numbers.
9
  Return the sum of those two numbers plus
10
  the sum of all the numbers between them.
11
  The lowest number will not always come
12
  first.
13

14
  Returns an integer.
15

16
  source: [Sum All Numbers in a Range](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-numbers-in-a-range)
17

18
  ## Examples
19

20
      iex> IntermediateAlgo.sum_all([1, 4])
21
      10
22

23
      iex> IntermediateAlgo.sum_all([4, 1])
24
      10
25

26
      iex> IntermediateAlgo.sum_all([0, 0])
27
      0
28

29
      iex> IntermediateAlgo.sum_all([5, 10])
30
      45
31

32
  """
33
  @doc since: "0.1.0"
34
  @spec sum_all([integer]) :: integer
35
  def sum_all([0, 0]), do: 0
1✔
36

37
  def sum_all([num_one, num_two] = _list) do
38
    to_list(num_one, num_two, [])
39
    |> sum()
103✔
40
  end
41

42
  @spec to_list(integer, integer, [integer]) :: [integer]
43
  defp to_list(num_one, num_two, list) when num_one === num_two do
44
    list ++ [num_one]
103✔
45
  end
46

47
  defp to_list(num_one, num_two, list) when num_one <= num_two do
48
    to_list(num_one + 1, num_two, list ++ [num_one])
750✔
49
  end
50

51
  defp to_list(num_one, num_two, list) when num_one >= num_two do
52
    to_list(num_one - 1, num_two, list ++ [num_one])
802✔
53
  end
54

55
  @spec sum([integer]) :: integer
56
  defp sum([]), do: 0
103✔
57
  defp sum([h | t] = _list), do: h + sum(t)
1,655✔
58

59
  @doc """
60
  Compare two arrays and return a new array
61
  with any items only found in one of the
62
  two given arrays, but not both. In other
63
  words, return the symmetric difference of
64
  the two arrays.
65

66
  It returns either an list of empty or
67
  unsorted element(s).
68

69
  source: [Diff Two Arrays](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays)
70

71
  ## Examples
72

73
      iex> IntermediateAlgo.diff_list(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"])
74
      ["diorite", "pink wool"]
75

76
      iex> IntermediateAlgo.diff_list(["andesite", "grass", "dirt", "dead shrub"],["andesite", "grass", "dirt", "dead shrub"])
77
      []
78

79
      iex> IntermediateAlgo.diff_list([1, 2, 3, 5], [1, 2, 3, 4, 5])
80
      [4]
81

82
      iex> IntermediateAlgo.diff_list([1, 2, 3, 5], [])
83
      [1, 2, 3, 5]
84

85
      iex> IntermediateAlgo.diff_list([1, "calf", 3, "piglet"], [1, "calf", 3, 4])
86
      [4, "piglet"]
87

88
  """
89
  @doc since: "0.1.0"
90
  @spec diff_list(list(any), list(any)) :: [] | list(any)
91
  def diff_list([], list), do: list
100✔
92
  def diff_list(list, []), do: list
1✔
93

94
  def diff_list(list_one, list_two),
95
    do: do_diff_list(list_one ++ list_two, [], [])
104✔
96

97
  defp do_diff_list([], _dups, result), do: result
104✔
98

99
  defp do_diff_list([h | t], dups, result) do
100
    if h in t or h in dups do
1,265✔
101
      do_diff_list(t, [h | dups], result)
82✔
102
    else
103
      do_diff_list(t, dups, [h | result])
1,183✔
104
    end
105
  end
106
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc