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

Chapter 4 - mean with callback not works #43

Open
marcosfromrio opened this issue Jan 27, 2019 · 1 comment
Open

Chapter 4 - mean with callback not works #43

marcosfromrio opened this issue Jan 27, 2019 · 1 comment

Comments

@marcosfromrio
Copy link

JS novice to Ninja >>> node

function mean(array, callback) {
... if (callback) {
..... array.map(callback);
..... }
...
... const total = array.reduce((a, b) => a + b);
... return total / array.length;
... }
undefined
mean([8, 4, 7, 9], x => x*2);
7
mean([8, 4, 7, 9]);
7

@daz4126
Copy link
Collaborator

daz4126 commented Feb 20, 2019

Sorry for the long delay in replying!

This is because map doesn't mutate the array. The code in the if block needs changing to:

if (callback) {
 a = array.map(callback);
 }

Hope that helps!

Daz
cc @simonmackie (to update code in ebook)

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

2 participants