Skip to content

working arrays - #170

Open
rverdi642 wants to merge 4 commits into
bloominstituteoftechnology:masterfrom
rverdi642:master
Open

working arrays#170
rverdi642 wants to merge 4 commits into
bloominstituteoftechnology:masterfrom
rverdi642:master

Conversation

@rverdi642

Copy link
Copy Markdown

Richard Verdier

@TERR1E TERR1E left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi Richard, great progress so far 👍
Here are some helpful links for ES6 arrow syntax and closure:

http://exploringjs.com/es6/ch_arrow-functions.html

Closure & Callbacks: https://gist.github.com/amysimmons/3d228a9a57e30ec13ab1

@dtacheny dtacheny left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work! Let me know if you have any questions/need clarification about .filter or closure.

Comment thread assignments/closure.js
}
}

counter();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There are a few small errors in this block. The logic is correct!

Line 5: That first curly brace shouldn't be there. It's closing off the counter function, so the return is cut out. Also, the return statement shouldn't wrapped in curly braces since that's being interpreted as an Object.

On line 12, you're invoking the counter function, but you aren't assigning the result to anything. The goal is to be able to invoke the function that's returned as a result of invoking counter(), so you could do something like this:

const newCounter = counter();

Since the counter function is returning an anonymous function, this line is effectively the same as this:

const newCounter = function() {
  counter = counter + 1;
  return counter;
}

but because of closure, newCounter will have access to the counter variable inside of the function! So then you can invoke newCounter and it will increment the counter variable.

console.log(newCounter()) // will print out 1
console.log(newCounter()) // will print out 2

I would also recommend naming the counter variable something different from the name of the function, for clarity.

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.

3 participants