list question

54 views
Skip to first unread message

Roelof Wobben

unread,
Feb 2, 2015, 3:00:42 PM2/2/15
to nod...@googlegroups.com
Hello,

I doing exercises of nodeschool.

I have to filter some data in a list so I did

~~~

for (var i=0, i < list.length , i++ ) {

     if file.ext = ext then  {
          console.log(print item[i]
}
}

but in the official solution I see this :

~~~

List.foreach {
  if file.ext = ext then {
     console.log(item[i]
}
}  

~~~

where can I find more info on the list properties ?

Roelof

Thomas Shinnick

unread,
Feb 2, 2015, 4:38:57 PM2/2/15
to nod...@googlegroups.com
Whenever you see something you don't recognize, that just might be part of Javascript you didn't know about, try checking with one of the Javascript reference sites.  I'm sure there are a few opinions which is 'best', but I just check the Mozilla site, such as searching for "mdn javascript foreach" with Google which gets you to Array.prototype.forEach()
But what you have cited seems to be missing a callback reference, like

list.foreach( function(file){ 
  if file.ext = ext then {
     console.log(item[i]
  }
});

Can you look at that "official answer" again?

Roelof Wobben

unread,
Feb 3, 2015, 1:43:34 AM2/3/15
to nod...@googlegroups.com
Thanks, maybe I made a typo but I will look again.

Problem solved.

Roelof


Op maandag 2 februari 2015 22:38:57 UTC+1 schreef Thomas Shinnick:

Alexander Praetorius

unread,
Feb 3, 2015, 12:55:42 PM2/3/15
to nod...@googlegroups.com
For me:
List.foreach {
  if file.ext = ext then {
     console.log(item[i]
}
}
looks very strange and does not execute in my javascript console.
Is that coffeescript mixed with es6 and/or promises or something?

1. foreach is followed by "{"?
2. what is "ext then {"?
3. "console.log(item[i]" ...has no closing ")"?

Is there something missing?
Is that javascript?


--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/d4eba874-0903-4623-b7fb-579df3e2b0e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ryan Schmidt

unread,
Feb 3, 2015, 12:55:57 PM2/3/15
to nod...@googlegroups.com

On Feb 2, 2015, at 3:38 PM, Thomas Shinnick wrote:

> Whenever you see something you don't recognize, that just might be part of Javascript you didn't know about, try checking with one of the Javascript reference sites. I'm sure there are a few opinions which is 'best', but I just check the Mozilla site, such as searching for "mdn javascript foreach" with Google which gets you to Array.prototype.forEach()
> But what you have cited seems to be missing a callback reference, like
>
> list.foreach( function(file){
> if file.ext = ext then {
> console.log(item[i]
> }
> });
>
> Can you look at that "official answer" again?

Let's also not forget to capitalize "forEach" correctly; that we need parentheses around the conditional; that we want to compare, not assign; that there is no such JavaScript keyword as "then"; and that in the revised code, there is no variable "i":


list.forEach(function (file) {
if (file.ext == ext) {
console.log(file);
}
});


There's also no such thing as a "list" in JavaScript; it's called an "array". More here:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array


Reply all
Reply to author
Forward
0 new messages