Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions javascripting/accessing-array-values.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var food = ['apple', 'pizza', 'pear'];
console.log(food[1]);
6 changes: 6 additions & 0 deletions javascripting/array-filtering.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var numbers = [1,2,3,4,5,6,7,8,9,10];
var filtered = numbers.filter(function evenNumbers(number){
Copy link
Member

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;
});

Copy link
Author

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.

Copy link
Author

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
.

Copy link
Member

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;
});

Copy link
Author

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!

return number % 2 === 0;
});

console.log(filtered);
3 changes: 3 additions & 0 deletions javascripting/arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var pizzaToppings = ['tomato sauce', 'cheese', 'pepperoni'];

console.log(pizzaToppings);
8 changes: 8 additions & 0 deletions javascripting/for-loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var total = 0;
var limit = 10;

for(var i = total; i < limit; i++){
total += i;
}

console.log(total);
5 changes: 5 additions & 0 deletions javascripting/function-arguments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function math(a,b,c){
return b * c + a;
}

console.log(math(53, 61, 67));
5 changes: 5 additions & 0 deletions javascripting/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function eat (food) {
return food + ' tasted really good.';
}

console.log(eat('bananas'));
6 changes: 6 additions & 0 deletions javascripting/if-statement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var fruit = 'orange';
if(fruit.length > 5){
console.log("The fruit name has more than five characters.");
}else {
console.log("The fruit name has five characters or less.");
}
1 change: 1 addition & 0 deletions javascripting/introduction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello');
6 changes: 6 additions & 0 deletions javascripting/looping-through-arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var pets =['cat', 'dog', 'rat'];
for(var i = 0; i < pets.length; i++){
Copy link
Member

Choose a reason for hiding this comment

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

what would be the benefit of maybe doing the following instead?

var petsLength = pets.length
for (var i = 0; i < petsLength; i++) {

pets[i] = pets[i] + 's';
}

console.log(pets);
2 changes: 2 additions & 0 deletions javascripting/number-to-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var n = 128;
console.log(n.toString());
2 changes: 2 additions & 0 deletions javascripting/numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var example = 123456789;
console.log(example);
5 changes: 5 additions & 0 deletions javascripting/object-properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var food = {
types: 'only pizza'
};

console.log(food.types);
7 changes: 7 additions & 0 deletions javascripting/objects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var pizza = {
toppings: ['cheese', 'sauce', 'pepperoni'],
crust: 'deep dish',
serves: 2
};

console.log(pizza);
2 changes: 2 additions & 0 deletions javascripting/revising-strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var pizza = 'pizza is alright';
console.log(pizza.replace('alright', 'wonderful'));
3 changes: 3 additions & 0 deletions javascripting/rounding-numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var roundUp = 1.5;
var rounded = Math.round(roundUp);
console.log(rounded);
2 changes: 2 additions & 0 deletions javascripting/string-length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var example = 'example string';
console.log(example.length);
2 changes: 2 additions & 0 deletions javascripting/strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var someString = 'this is a string';
console.log(someString);
2 changes: 2 additions & 0 deletions javascripting/variables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var example = 'some string';
console.log(example);