FAQ: Iterators - Iterator Documentation

thank you for explaining, it helped to clarify when I’ll use return :grin: :grin: :grin:

1 Like


… for a look at this later. You can fork it and play around with it. Mostly, learn from it.

1 Like

This entire lesson, I feel, is confusing and relies too heavily on pointing us to free resources (namely, the MDN). For those of us who choose to pay for Pro, this is especially frustrating. Everyone in the Codecademy community is using this platform to learn to code – and of course, a part of that requires teaching us to be resourceful, but I feel like Codecademy is being a little lazy here. This lesson is poorly written and very confusing, and once someone gets to this point, it is easy for them to give up.

Maybe I’m just a little cranky today …

Not only beginners are expected to rely upon documentation, everyone is. Authors and developers treat these resources as their guiding light, and so should learners. CC may seem to be pushing learners there, but it is for their benefit, not to make up for any perceived laziness on CC’s part.

1 Like

I get it. I’ve been developing since 1999 and I learned a lot just by looking things up. I guess I just feel like this lesson isn’t well written, which is frustrating, and then it directs me to a free resource. But it may be entirely possible that I just woke up on the wrong side of the bed this morning :laughing:

1 Like

ok i just finished the previous exercise and getting here i realised ‘accumulator’ and ‘currentValue’ were not defined the way they should behave… are they keywords in JS??

No, not keywords. They are descriptive variable names. The first variable holds the cumulative value, the second variable is next term in the array.

It is common to see,

[1,2,3,4,5,6,7,8,9,10].reduce((a, b) => a + b)

This is all handled internally by the iterator so if we wish to watch it work it will mean expanding the function and logging the variables. We can visualize it, like so,

a    b
1,  [2,3,4,5,6,7,8,9,10]
3,  [3,4,5,6,7,8,9,10]
6,  [4,5,6,7,8,9,10]
10, [5,6,7,8,9,10]
15, [6,7,8,9,10]
21, [7,8,9,10]
28, [8,9,10]
36, [9,10]
45, [10]
1 Like

Hello @stetim94.
To that end regarding the interestingWords.every code that we need to “fix”:

I gave up after being unable to get the function defined and consulted the hint, however why is (word) needed to be in its own parentheses in this code? Am I correct calling it a single parameter?

// console.log(interestingWords.every(word => word     ));

In other examples it appeared (word => { return word.method} sufficed.
I’m trying to not give much more away for those who don’t care for a spoiler.

Upon reviewing of the filled in hint vs my own prior answer, It should be noted on the second question regarding the filter, I passed the question without putting the single parameter (word) in it’s own parentheses.

Thanks for your time.

When the function has a single parameter, the brackets can be omitted. This is a shorthand. Doesn’t mean you have to use the shorthand.

All is noted on the brackets.
As always, thanks for taking the time to clarify this for me. Much appreciated.

Roy what do you mean by “Single Statement” ? sorry i’m struggling when to use the {} because in some exercises in this Iterators chapter i was using single-line block without ‘Return’ and Without {}.
Thank You :slight_smile:

When a function has more than one statement it must have curly braces and a return keyword (as opposed to implicit return). When it has only one statement the syntax is relaxed. There is still a potential return, though.

Arrow functions really prove their worth when the statement is not a directive, but rather, an expression. If we want our function to do something, then I like to use braces, and leave out the return. If we want it to return something, then put that something in the form of an expression.

x => x ** 2         // implicit return

x => {
  console.log(x)    // return undefined

Sure this will work the exact same way…

x => console.log(x)    // return undefined

but sometimes how we write gives signals so we don’t need to comment. The above is a perfect example of code that describes itself, however subtle.

const f = x => x ** 3
const g = x => console.log(x)
g(f(5))    //  125
1 Like

What is really funny about the above is that we could define g without using a function.

const g = console.log

g(f(6))    //  216

In this sense, we may as well give it a purpose based name…

const log = console.log

Wrap your head around that and get back to us.

Hi there

I am unable to see the words ARRAY as described in question 1. On the right side of the code editor part to complete the exercise can someone please check

const newNumbers = [1, 3, 5, 7];

const newSum = newNumbers.reduce((accumulator, currentValue) => {

  console.log('The value of accumulator: ', accumulator);

  console.log('The value of currentValue: ', currentValue);

  return accumulator + currentValue;

}, 10);


Folllwing the screen i am able to see.


The code on the right is entirely disparate with what is suggested on the left. Have you tried to Reset the exercise?

Just a note there seems to be some differences between the code on the left and the code on right:

The exercise says there’s a code commented out:

// console.log(interestingWords.every(word =>        ));

Whereas the code on the right is:

// console.log(interestingWords.every((word) => { } ));

One is shorthand. Both syntaxes are allowed.

I’m not disputing that. I’m just pointing out the differences. You can’t say ‘There is this code’ when there isn’t in fact.

1 Like

Thank you Its fixed now

1 Like

console.log(interestingWords.every**((word)** => { 
  return word.length > 5
 } ));

Hi, I was wondering why in the last portion of the activity, I had to use the function of “word” instead of “words”, considering “word” is a completely different function.