These are chat archives for LPM42/JavaScript_Foundations_2

8th
Dec 2014
Mel Quark
@mel-quark
Dec 08 2014 01:12
slide 34 has typos. the asserts should look like this:
assert(_.contains(intToChar([1,2,3]),"a"));
assert(_.contains(intToChar([1,2,3]),"b"));
assert(_.contains(intToChar([1,2,3]),"c"));
Livingston Martin
@LPM42
Dec 08 2014 02:53
How to send code in gitter:
``` before and after your code. Like this:
console.log(“some code”);
'P divy' (Ingrid)
@icuthy
Dec 08 2014 21:03
console.log(“Thanks, good to know!”);
Hiro-Protagonist
@Hiro-Protagonist
Dec 08 2014 21:37
ok
so
can't find any good info on foreach loops
I'm at
array.forEach(product *=)
and just can't figure out where to go from there
Jayden0306
@Jayden0306
Dec 08 2014 21:41
U need to include the function in for each
Hiro-Protagonist
@Hiro-Protagonist
Dec 08 2014 21:42
ah
Gaye
@gayegul
Dec 08 2014 21:43
array.forEach(parameter here) {
code block here
}
Jayden0306
@Jayden0306
Dec 08 2014 21:45
var a = ["a", "b", "c"];
a.forEach(function(entry) {
console.log(entry);
});
Hiro-Protagonist
@Hiro-Protagonist
Dec 08 2014 21:50
thanks all!
nope
still confused
:(
so.
Hiro-Protagonist
@Hiro-Protagonist
Dec 08 2014 21:57
faugh
can't figure out how to make this make sense
so upset
Gaye
@gayegul
Dec 08 2014 21:58
No don't be upset! You are so close almost there! Your (product *=) idea was right but in wrong place. That is your code block. You can complete that block by using what parameter you pass in your function.
Hiro-Protagonist
@Hiro-Protagonist
Dec 08 2014 21:58
hrmmmmm
array.forEach(product){
    return product *= array;
}
is the most sense I can make of this
which is bvs wrong
*obvs
Gaye
@gayegul
Dec 08 2014 22:01
instead of passing 'product' you literally need to pass a function like .forEach (function(another parameter here) { ...}
my team mate and I will be meeting at 5 at CodeFellows to complete yesterday's lab we can go over it if you want.
Hiro-Protagonist
@Hiro-Protagonist
Dec 08 2014 22:04
ok!
Hiro-Protagonist
@Hiro-Protagonist
Dec 08 2014 22:51
ok ok
how about this
array.forEach(multiply(number){
return product *= number;
});
array.forEach(multiply(number){
    return product *= number;
});
brandonburns
@brandonburns
Dec 08 2014 22:52
So im still a little confused on quiz 4. I completely understand what the if statement does ( if(!array || !array.length)), but what confuses me is when i try to explain it. I get that it checks to make sure that the input is an array before sending it to the for loop, but what i dont understand is why it needs more than !array. i know that array.length checks an array and returns how many characters it has, but i dont specifically understand what it is doing inside this if statement. in what scenario would !array fail, but !array.length return a null, and what about array.length shows that it is not an array? Thanks
Hiro-Protagonist
@Hiro-Protagonist
Dec 08 2014 22:54
I THINK it would be if it was an empty array
correct?
like
if somebody created an array
var array = [];
without any length
although I'm baffled why that didn't also check for !NaN
Gaye
@gayegul
Dec 08 2014 23:00
I believe it checks if the array is undefined by !array @brandonburns
@Hiro-Protagonist you got it but there is a small problem with the word 'multiply'. it should be an anonymous function with the word 'function' instead. You are not calling a predefined function you are creating one. (if I am not mistaken of course)
brandonburns
@brandonburns
Dec 08 2014 23:02

Thanks hiro and gaye, thats what i kinda thought and i just made a test in sublime to seevar brandon = [];

function check(array) {
if (!array.length) {
console.log("not an array");
}
}

check(brandon);

it logs "not an array"
so we are right, !array.length makes sure that it is atleast 1 character, although the array can still be defined wihtout one
Hiro-Protagonist
@Hiro-Protagonist
Dec 08 2014 23:08
:)