-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
Hi @BigSpaces
YES. You understand the problem and have the right idea for a possible solution.
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 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)
Pushing your local changes on the 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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,