-
Notifications
You must be signed in to change notification settings - Fork 31
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
I'm done javascripting #6
base: master
Are you sure you want to change the base?
Conversation
Nice 👍 |
@@ -0,0 +1,6 @@ | |||
var numbers = [1,2,3,4,5,6,7,8,9,10]; | |||
var filtered = numbers.filter(function evenNumbers(number){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to name the callback function here unless specified by the drill.
var filtered = numbers.filter( function(number){
return number % 2 === 0;
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok nice!
On Apr 11, 2015 7:42 PM, "jaybobo" [email protected] wrote:
In javascripting/array-filtering.js
#6 (comment)
:@@ -0,0 +1,6 @@
+var numbers = [1,2,3,4,5,6,7,8,9,10];
+var filtered = numbers.filter(function evenNumbers(number){No need to name the callback function here unless specified by the drill.
var filtered = numbers.filter( function(number){
return number % 2 === 0;
});—
Reply to this email directly or view it on GitHub
https://github.com/paircolumbus/javascripting101/pull/6/files#r28199361.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it have something to do with possibly editing the array within the for
loop without affecting the limit of the for loop?
On Apr 11, 2015 7:44 PM, "Jaron Murphy" [email protected] wrote:
Oh ok nice!
On Apr 11, 2015 7:42 PM, "jaybobo" [email protected] wrote:In javascripting/array-filtering.js
#6 (comment)
:@@ -0,0 +1,6 @@
+var numbers = [1,2,3,4,5,6,7,8,9,10];
+var filtered = numbers.filter(function evenNumbers(number){No need to name the callback function here unless specified by the drill.
var filtered = numbers.filter( function(number){
return number % 2 === 0;
});—
Reply to this email directly or view it on GitHub
https://github.com/paircolumbus/javascripting101/pull/6/files#r28199361
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly, JS like some other languages embraces the idea of anonymous functions or lambdas which are functions without identifiers. They can be passed around like normal variables. So in the case where maybe you're passing in some callback function that's really large, you can just use an anonymous function instead.
This would have also worked...
function evenNumbers(num) {
//lets say your doing a bunch of
//other stuff here.
return n % 2 == 0;
}
numbers.filter(evenNumbers)
but because your function body is small, this could be preferable.
numbers.filter(function(num) {
return n % 2 == 0;
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I get it! That makes a lot of sense. Thanks!
@jaybobo check this out!