Skip to content
This repository was archived by the owner on Jun 7, 2019. It is now read-only.

Elixir append list#58

Open
jmbejar wants to merge 3 commits intomasterfrom
elixir-append-list
Open

Elixir append list#58
jmbejar wants to merge 3 commits intomasterfrom
elixir-append-list

Conversation

@jmbejar
Copy link
Member

@jmbejar jmbejar commented Jan 14, 2019

No description provided.


## The problem

Let's say we need to implement a function that receives a list of integers and returns a list including those numbers repeated several times, as it is showed in the following examples:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I would replace the several times with the more specific description below the example to make it clearer (and remove the second description of the problem)


## Our first naive implementation

We could say that a very simple solution to this problem could be an approach where we use `Enum.reduce/3` and repeat each number, concatenating the list of repeated values to the accumulated list.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence feels a little repetitive to me because of the many could.

Maybe something like this might sound better (not really sure n_n")

A very simple solution to this problem could be using `Enum.reduce/3` and repeat each number ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Liked it


In my machine this is running **in approximately 11ms**! It is a huge difference, and this is proportional to the length of the list we are testing.

All good so far, but... are we sure that this is going to perform better in all cases? Well, we're not in a safe place yet. Let's run again our function using a different input.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's run our function again using a different input.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants