View Source FreecodecampElixir.IntermediateAlgo (Freecodecamp using Elixir v0.1.0)

Documentation for Freecodecamp (Intermediate Alogrithmic Scripting).

Link to this section Summary

Functions

Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.

We'll pass you an array of two numbers. Return the sum of those two numbers plus the sum of all the numbers between them. The lowest number will not always come first.

Link to this section Functions

Link to this function

diff_list(list, list)

View Source (since 0.1.0)
@spec diff_list([any()], [any()]) :: [] | [any()]

Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.

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

source: Diff Two Arrays

examples

Examples

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

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

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

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

iex> IntermediateAlgo.diff_list([1, "calf", 3, "piglet"], [1, "calf", 3, 4])
[4, "piglet"]
Link to this function

sum_all(list)

View Source (since 0.1.0)
@spec sum_all([integer()]) :: integer()

We'll pass you an array of two numbers. Return the sum of those two numbers plus the sum of all the numbers between them. The lowest number will not always come first.

Returns an integer.

source: Sum All Numbers in a Range

examples

Examples

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

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

iex> IntermediateAlgo.sum_all([0, 0])
0

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