Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(COMPLETE) Number Finder #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

(COMPLETE) Number Finder #2

wants to merge 1 commit into from

Conversation

BigSpaces
Copy link
Owner

Hello @BrooklinJazz

I am struggling with two things, but first, my logic

Using reduce, I want to go through each element of the list. If the current number is smaller than the accumulator, then assign that value to the accumulator. I have tried a few different ways, mainly "if do end", but I always manage to get compile errors.

I do not know how to pass a "neutral" accumulator. If I set the default as an empty variable, such as "smallest", Elixir tells me it has not been defined. If I do not define it, does Elixir keep the accumulator... where?

Finally, I seem to only be able to pull requests into my main branch? If I do this, won't I lose all progress next time I sync with the DockYard-Academy/beta_curriculum repository? - Will be good to review the video to understand how to upload my progress without losing changes. When I push from my terminal all changes are uploaded to my remote repository in my "number finder" branch, but I do not know how to leave a comment with that push.

Thank you,

@BrooklinJazz
Copy link

Hi @BigSpaces

Using reduce, I want to go through each element of the list. If the current number is smaller than the accumulator, then assign that value to the accumulator.

YES. You understand the problem and have the right idea for a possible solution.

I do not know how to pass a "neutral" accumulator. If I set the default as an empty variable, such as "smallest", Elixir tells me it has not been defined. If I do not define it, does Elixir keep the accumulator... where?

If your accumulator will be the smallest value, what about using the first value of the list? It's by default the smallest value so far right? The first accumulator is either the first element for Enum..reduce/2 or the provided initial accumulator for Enum.reduce/3. The next accumulator is the return value of the callback function.

The accumulator is bound to the second parameter of the callback function. For example:

Enum.reduce([1, 2, 3], fn integer, accumulator -> "return value will be the next accumulator" end)

Finally, I seem to only be able to pull requests into my main branch? If I do this, won't I lose all progress next time I sync with the DockYard-Academy/beta_curriculum repository?

main won't have your exercise changes, but you won't lose any progress because it's stored on the remote NumberFinder branch. Just don't merge in this PR into your main branch and it will always track our comments on the exercise.

when I push from my terminal all changes are uploaded to my remote repository in my "number finder" branch, but I do not know how to leave a comment with that push.

Pushing your local changes on the NumberFinder branch uploads them to your remote NumberFinder branch on GitHub. Each commit will have a message associated with it. You can also leave comments by commenting on the pull request.

There is no way of associating a comment with a specific "push", but that's not desirable given you can instead comment on this PR and it will show that your comment was made AFTER pushing your changes.

## Enum.min(number_list) - This works
## Enum.reduce([1, 2, 3], fn(number, acc) -> if number < acc do number end end)
Enum.reduce(number_list, 4, fn number, smallest ->
if number < smallest do

Choose a reason for hiding this comment

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

What is your else case?

Remember that if number < smallest is false if will return nil. Then your next accumulator is nil and your code will run into problems.

Choose a reason for hiding this comment

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

Your initial accumulator is 4 here. That works because it's larger than any element in the list. You made a comment about not having a good neutral accumulator, so what if your accumulator was just the first element in your list?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thank you! Concepts start to be clarified in my head. Yesterday's class also helped a lot.

@BigSpaces BigSpaces changed the title Number Finder (COMPLETE) Number Finder Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants