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

Exercise 19: Reducing with an initial value #69

Open
haveagoodone opened this issue Jun 22, 2015 · 3 comments
Open

Exercise 19: Reducing with an initial value #69

haveagoodone opened this issue Jun 22, 2015 · 3 comments

Comments

@haveagoodone
Copy link

If I console.log() the result of this exercise, it is not like the expected one:

[
  {
    "65432445": "The Chamber",
    "675465": "Fracture",
    "70111470": "Die Hard",
    "654356453": "Bad Boys"
  }
]

it looks like this:

[
  {
    "654356453": "Bad Boys"
  }
]

Is the expected output wrong or just the solution?

Thanks for the great Exercises at all.

@wwwfreedom
Copy link

I had the same result. It took me a while to figure it out.
The expected output is using the implementation of the reduce function from exercise 16, which returns an array of accumulated values. You are using the standard reduce method from the Array.prototype object in Javascript, which only returns a single accumulated value. To get the desired output just add reduce implementation from exercise 16 to the Javascript Array.prototype.

Cheers!

@HaveF HaveF mentioned this issue Oct 30, 2015
@HaveF
Copy link

HaveF commented Oct 30, 2015

@wwwfreedom thanks for your explanation:smile: . And btw, what should I do about the different behavior of them in real world?

@HaveF
Copy link

HaveF commented Oct 30, 2015

#44 Reduce returns an array, not a value
which is a very detailed explanation about reduce/fold thing

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

No branches or pull requests

3 participants