These are chat archives for FreeCodeCamp/Help

27th
Feb 2015
Germaine Pannell
@germainep
Feb 27 2015 00:16
Phillip Ventura
@fvntr
Feb 27 2015 00:17
what is the z variable for?
i dont see it being used in any other part of the code
Cristián Berríos
@crisberrios
Feb 27 2015 00:18
I saw someone posted a much shorter approach to this problem
but yours isn't wrong
you have the core logic right
Germaine Pannell
@germainep
Feb 27 2015 00:18
the z was for a test
Cristián Berríos
@crisberrios
Feb 27 2015 00:18
so (for every item in A, if it's not in B, push it),(for every item in B, if it's not on A, push it)
Phillip Ventura
@fvntr
Feb 27 2015 00:19
@crisberrios do you know where to find the other approach
Cristián Berríos
@crisberrios
Feb 27 2015 00:19
@fvntr wait
Germaine Pannell
@germainep
Feb 27 2015 00:19
some how I'm creating an infinite loop if there are more than two arguments
Cristián Berríos
@crisberrios
Feb 27 2015 00:20
in this case, .reduce comes of great help
[[[a,b],c],d]
but diff is not returning anything
or does it?
my bad
Germaine Pannell
@germainep
Feb 27 2015 00:22
it returns newArr
Cristián Berríos
@crisberrios
Feb 27 2015 00:23
check where you are defining args
wait, let me check the code in a js enviroment
ok
I see it now
check where are you defining newArr
and how reduce works
Germaine Pannell
@germainep
Feb 27 2015 00:32
ok i understand why its doing what its doing now I just need to figure out how to make it stop
Cristián Berríos
@crisberrios
Feb 27 2015 00:34
for now, you'd want to move newArr definition inside the diff function
so it starts clean on each iteration of reduce
but the function is still missing a couple things, you're on right track though
just added minimum things to make your function work.
@fvntr the other method is 1st: "concatenate all arguments in to 1 array", step 2 "for each entry, if indexOf(entry) !== lastIndexOf(entry) then it's not unique. Else, push it.
Germaine Pannell
@germainep
Feb 27 2015 00:38
i see but I've invested so much time into this method I might as well see it through
Cristián Berríos
@crisberrios
Feb 27 2015 00:39
sure germaine
you are just 2 or 3 lines of code away from finishing it
Oliver
@Dadsaster
Feb 27 2015 00:41

'''
function sym(arr) {
var longList = [];
var result = [];
var elem;

// make one big array
for (i = 0 ; i < arguments.length ; i++) {
    for (k = 0 ; k < arguments[i].length; k++) {
        longList.push(arguments[i][k]);
    }

}
//take one element from the array
while (longList.length) {
    elem = longList.pop();
    // if it doesn't exist anywhere in the array - move it to a new array
    if (longList.indexOf(elem) === -1) {
        result.push(elem);
    // else remove all copies of elem
    } else {
        // don't stop until you get them all
        do {
            var index = longList.indexOf(elem);
            longList.splice(index,1);
        }while (longList.indexOf(elem) !== -1);
    }

}
return result;

}
sym([1,2,3,5],[1,5,4],[1,3,6,7]);
'''

Phillip Ventura
@fvntr
Feb 27 2015 00:43
@Dadsaster that doesnt work for repeated elements
Oliver
@Dadsaster
Feb 27 2015 00:43
sure it does
Phillip Ventura
@fvntr
Feb 27 2015 00:44
sym([1,1],[1]) returns an empty arr when i run it
Oliver
@Dadsaster
Feb 27 2015 00:44
there are no unique items
which it should
unless I totally misunderstood the challenge
Phillip Ventura
@fvntr
Feb 27 2015 00:46
the specs require to push elements that dont appear even if theyre not unique
so sym( [1,1],[1]) should return [1]
since there's no other element to cancel it out
Oliver
@Dadsaster
Feb 27 2015 00:48
does sym([1,2,3],[1,2]) return [3] or [1,2,3]?
Phillip Ventura
@fvntr
Feb 27 2015 00:50
3
Oliver
@Dadsaster
Feb 27 2015 00:50
okay - so I have to add a condition of all elements in all arrays being the same - thanks for clarifying
Cristián Berríos
@crisberrios
Feb 27 2015 00:51
keep it simple @Dadsaster
Oliver
@Dadsaster
Feb 27 2015 00:52
You should have seen what I started with :)
I'll take a look at reduce
Germaine Pannell
@germainep
Feb 27 2015 01:00
fix it got it. woot woot woot
Cristián Berríos
@crisberrios
Feb 27 2015 01:03
:thumbsup:
Jeroen
@teKoa
Feb 27 2015 01:32
anyone here?
Cristián Berríos
@crisberrios
Feb 27 2015 01:37
:shipit:
Jeroen
@teKoa
Feb 27 2015 01:40
I just did the codecademy FizzBuzz assignment. Quincy said it was a tough assignment that could be asked at job interviews and I apparently did it correctly according to the site but not sure if my code is good or if I did a long roundabout way about doing it. Mind having a look at it?
I never posted code before in here so if this goes wrong then I am sorry
var counter = 20;

for (var i = 1; i <= counter; i++) {
    if ((i % 5 == 0) && (i % 3 == 0)){
        console.log("FizzBuzz");
    } else if (i % 5 == 0) {
        console.log("Buzz");
    } else if (i % 3 == 0) {
        console.log("Fizz");
    } else {
        console.log(i);
    }
}
guess it went wrong
Cristián Berríos
@crisberrios
Feb 27 2015 01:49
let's see
Phillip Ventura
@fvntr
Feb 27 2015 01:49
it works when i ran it
Cristián Berríos
@crisberrios
Feb 27 2015 01:49
well... that would be a standard answer
nothing to brag about
Jeroen
@teKoa
Feb 27 2015 01:51
well, standard works for me I suppose. Just making sure I didn't make it excessively long
Cristián Berríos
@crisberrios
Feb 27 2015 01:51
for (var i = 1; i <= counter; i++) {
    if (i % 15 === 0){
        console.log("FizzBuzz");
    } else if (i % 5 == 0) {
        console.log("Buzz");
    } else if (i % 3 == 0) {
        console.log("Fizz");
    } else {
        console.log(i);
    }
}
1st small refactor
Jeroen
@teKoa
Feb 27 2015 01:52
Ahh of course
thank you
Cristián Berríos
@crisberrios
Feb 27 2015 01:54
there are shorter ways but it can't get much faster
str = '';
if (i%3 === 0 ) str+= "Fizz";
if(i%5 === 0) str+= "Buzz";
console.log(str || i);
Jeroen
@teKoa
Feb 27 2015 01:59
oh wow
Cristián Berríos
@crisberrios
Feb 27 2015 02:00
but ithat form is slower
since you have to do 2 calculations on each loop
in the 1st you'll do 1 on some, 2 on some and 3 on some
3,3,2,3,2,2,3,3,2,2
for [1-10] it's actually faster
I'd have to test, it might be faster :P
Christian
@crisxian
Feb 27 2015 02:50
I'm on the blinking CSS robot project. So is keyframe animation suppose to overwrite all the CSS properties under .brain class? the Height and width of the gradient seems to go back to the default size. The two white eyes blinks into a single glowing red eye
@keyframes blink {
  50% {
    background: radial-gradient(circle, red 15%, transparent 40%), #cc5;
  }
}

.brain {
  animation: blink .5s infinite;
  -webkit-animation: blink .5s infinite;
  -moz-animation: blink .5s infinite;
  //.... everything else
}
Cristián Berríos
@crisberrios
Feb 27 2015 03:35
nope
you also need a -moz-keyframes
and -webkit-keyframes
Kiy-Hong Tang
@kiytang
Feb 27 2015 10:34
hi @crisberrios very curious how you test load speeds on js. Is there a application that we can use to test? many thanks in advance
Cristián Berríos
@crisberrios
Feb 27 2015 14:19
sure
console.time....console.timeEnd @kiytang
also cpu profiling in devtools
Danny Fritz
@dannyfritz
Feb 27 2015 16:17
yeah, profiler is your friend for doing performance audits
cerissa
@cerissa
Feb 27 2015 16:45
ok anyone here want to help me thru my first bonfire?

this is what they are asking Return the factorial of the provided integer.

If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.

Factorials are often represented with the shorthand notation n!

For example: 5! = 1 2 3 4 5 = 120f

and this is the code they give
function factorialize(num) {
  return  num;
}

factorialize(5);
Cristián Berríos
@crisberrios
Feb 27 2015 16:47
ok
they give you the function name and number of parameters
cerissa
@cerissa
Feb 27 2015 16:48
i ran an if statment and got a return back of 0 1 5 but that wasnt what they were asking for apparently
Cristián Berríos
@crisberrios
Feb 27 2015 16:48
you can modify everything inside the curly braces
and then you can see the test results in the left part
for 5 it should be 1*2*3*4*5 = 120
and you don't have to return num
it can be any variable or function you define
cerissa
@cerissa
Feb 27 2015 16:49
ok
Cristián Berríos
@crisberrios
Feb 27 2015 16:49
also, you can modify the function call below
to any input you want
so you can test different cases
cerissa
@cerissa
Feb 27 2015 16:50
ok let me try a few things
Germaine Pannell
@germainep
Feb 27 2015 16:57
hi guys me again just need some one to check my math
function orbitalPeriod(arr) {
//Use 398600.4418 for GM. Look up any other values on wolfram alpha
  function time(elem){
    var op = 0;
    op = 2 * Math.PI*(Math.sqrt(Math.pow(elem.avgAlt + 6378, 3)/398600.4418));
    delete elem.avgAlt;
    elem.orbitalPeriod = Math.ceil(op);
    return elem;
  }
  var newArr = arr.map(time);
  return newArr;

}

orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}]);
the output keeps coming up high I'm pretty sure the constants are all correct
and when I enter the input into wolfram alpha i get the same ouput as my program
Cristián Berríos
@crisberrios
Feb 27 2015 17:06
use earth radius from Wolfram Alpha
and instead of Math.ceil use Math.round
but otherwise the code is fine :D
4TSG4X
@4TSG4X
Feb 27 2015 17:08
@germainep Where did you find that problem?
Oliver
@Dadsaster
Feb 27 2015 17:09
it's one of the last ones.
It's called Map the Debris I believe
@germainep 4 left - nice job
cerissa
@cerissa
Feb 27 2015 17:11
ok i just think im not ready for bonfires
Germaine Pannell
@germainep
Feb 27 2015 17:11
thanks i've been cranking away
Oliver
@Dadsaster
Feb 27 2015 17:11
@cerissa - you can do it
Germaine Pannell
@germainep
Feb 27 2015 17:12
@crisberrios the output I'm getting is 86433 but bonfire is looking for 86400
Oliver
@Dadsaster
Feb 27 2015 17:12
@cerissa just think through what needs to happen to turn 5 into 1,2,3,4,5 into 234*5
2 x 3 x 4 x 5
Cristián Berríos
@crisberrios
Feb 27 2015 17:15
@germainep did you change the earth radius?
Germaine Pannell
@germainep
Feb 27 2015 17:15
@cerissa they sort of build on each other and some of the things you learn in the early ones help you with the latter one
yes
Cristián Berríos
@crisberrios
Feb 27 2015 17:16
can you paste your current code?
Oliver
@Dadsaster
Feb 27 2015 17:17
@cerissa - also don't be afraid to pair - there are lots of people who are new to this stuff and having a buddy can really help
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:17
@cerissa I'm stuck on the same one
I just decided to read Eloquent JS amd come back to it
Oliver
@Dadsaster
Feb 27 2015 17:18
Does anyone know of an online course in algorithms that uses javascript?
Cristián Berríos
@crisberrios
Feb 27 2015 17:18
If you don't like the style of Eloquent because it's too eloquent, try finding this book http://shop.oreilly.com/product/0636920027065.do
Germaine Pannell
@germainep
Feb 27 2015 17:18
got it I was using the earths radius from the orbital period around earth calculation on wolfram alpha did another search and found it
Cristián Berríos
@crisberrios
Feb 27 2015 17:19
:thumbsup:
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:20
@crisberrios available online?
Germaine Pannell
@germainep
Feb 27 2015 17:20
@crisberrios you are the best
Cristián Berríos
@crisberrios
Feb 27 2015 17:20
@Dadsaster I have yet to find a good resource on algorithms for beginners, but CS50x is very good as intro to CS
@AmmarAliShah "yes but no", do your own research :P
For a more general reference you might also check JavaScript Succintly which is free.
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:21
@crisberrios found it
Cristián Berríos
@crisberrios
Feb 27 2015 17:21
but it's not really an intro to JS
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:21
@crisberrios link to that one?
cerissa
@cerissa
Feb 27 2015 17:21
function factorialize(num) {
  var answer ="";
  for(i=1; i<=5; i++){
   answer += i;

    answer +=  "*";




  }

  return answer;
}

factorialize(5);
Cristián Berríos
@crisberrios
Feb 27 2015 17:22
cerissa
@cerissa
Feb 27 2015 17:23
im so totally off base here
Cristián Berríos
@crisberrios
Feb 27 2015 17:23
@cerissa you're getting the exercise wrong
cerissa
@cerissa
Feb 27 2015 17:23
i know that
Cristián Berríos
@crisberrios
Feb 27 2015 17:23
what factorializing a number means
is multiplying the numbers
not returning a string representing the multiplication
factorialize(5) should return 120
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:36
@crisberrios do we use a for with a i--?
Cristián Berríos
@crisberrios
Feb 27 2015 17:36
not necessary, but it's an option
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:37
we can get it to decrease to 0 and set it to be >= 0
this way it won't go below zero
and count down from the number provided
Cristián Berríos
@crisberrios
Feb 27 2015 17:38
sure, you can count forward or backwards
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:38
but here's is where I'ms stuck
Where do I store them?
so that I can multiple them with each other
Cristián Berríos
@crisberrios
Feb 27 2015 17:38
where do you store anything in js?
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:38
variables of course
Cristián Berríos
@crisberrios
Feb 27 2015 17:39
of course
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:39
that's not what I meant
I meant more in the logic kind
Cristián Berríos
@crisberrios
Feb 27 2015 17:39
and since you are multiplying
what's the multiplication identity value?
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:39
*?
Cristián Berríos
@crisberrios
Feb 27 2015 17:39
no
for addition is 0
since a+0 = a
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:40
didn't learn this yet I guess
Cristián Berríos
@crisberrios
Feb 27 2015 17:40
that's 2nd grade :P
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:40
no not that
Cristián Berríos
@crisberrios
Feb 27 2015 17:40
but in any case
for multiplication, identity is 1
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:40
ah
Cristián Berríos
@crisberrios
Feb 27 2015 17:41
since a*1 = a
if you're looking for a starter value
try with that
Ammar Ali Shah
@AmmarAliShah
Feb 27 2015 17:41
Let me give it another go
cerissa
@cerissa
Feb 27 2015 17:59
@AmmarAliShah did you figure it out
if not here is a pair programming, that explains it, so you can see what needs to be done and why
Evan Davis
@davisec52
Feb 27 2015 18:03
Hi. Working on the Destroyer Bonfire challenge and don't
understand why the code below is failing. Would appreciate
pointers in the right direction.

function destroyer(arr) {
  var list = [];
  var i;
  for(i in arguments) {
      if(i > 0) {
          list.push(arguments[i]);
      }
  }
  var result = arr.filter(function(a) {
      if(a !== list[i]) {
          return a;
      }
  });

  return result;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Hannan Ali
@abdulhannanali
Feb 27 2015 18:07
@davisec52 What i have understood from your code is that you are pushing the array in the list too
Oliver
@Dadsaster
Feb 27 2015 18:08
arguments[0] is an array which shouldn't be pushed onto list
Hannan Ali
@abdulhannanali
Feb 27 2015 18:08
the elements which have to be destroyed starts from index 1
0 is the original array
Evan Davis
@davisec52
Feb 27 2015 18:08
@abdulhannanali j>0 should only push arguments greater than 0 into list.
@Dadsaster right--got it, but j>0, so I thought, should have prevented that, right?
Maybe no.
Hannan Ali
@abdulhannanali
Feb 27 2015 18:09
@davisec52 You are right
I just consoled it
Evan Davis
@davisec52
Feb 27 2015 18:10
yep
Hannan Ali
@abdulhannanali
Feb 27 2015 18:12
@davisec52 It's not iterating through the whole list for each element
Evan Davis
@davisec52
Feb 27 2015 18:13
@abdulhannanali Any idea why?
Hannan Ali
@abdulhannanali
Feb 27 2015 18:13
As you are using the linear approach
The list should go through each element of list
Evan Davis
@davisec52
Feb 27 2015 18:13
What do you mean?
Hannan Ali
@abdulhannanali
Feb 27 2015 18:13
for each a
Evan Davis
@davisec52
Feb 27 2015 18:13
I thought the nature of the function would cause that to happen.
This may be the root of my difficulty with this one. How would I correct it?
Cristián Berríos
@crisberrios
Feb 27 2015 18:15
@davisec52
Evan Davis
@davisec52
Feb 27 2015 18:15
@crisberrios
Cristián Berríos
@crisberrios
Feb 27 2015 18:15
1st big error is (for i in arguments)
since it will pass the argument value to i
but not the index
Evan Davis
@davisec52
Feb 27 2015 18:15
right
Cristián Berríos
@crisberrios
Feb 27 2015 18:16
if going that route
it should be for (i in Object.keys(arguments))
Evan Davis
@davisec52
Feb 27 2015 18:16
@crisberrios should I have sorted arguments for properties instead of values?
Cristián Berríos
@crisberrios
Feb 27 2015 18:16
that way it will pass the argument name (number) to i
Evan Davis
@davisec52
Feb 27 2015 18:17
ok
for(i in Object.keys(arguments)) {
      if(i > 0) {
          list.push(arguments[i]);console.log(list);
      }
no
Oliver
@Dadsaster
Feb 27 2015 18:20
the arguments object also has a length property - I still don't know the best way for dealing with an unknown number of arguments.
Evan Davis
@davisec52
Feb 27 2015 18:21
for(i in x) {
      if(i > 0) {
          list.push(x);console.log(list);
      }
  }
Sorry, having trouble getting stuff to copy properly
Cristián Berríos
@crisberrios
Feb 27 2015 18:23
(function () {
var list = [];
for(i in Object.keys(arguments)) {
      if(i > 0) {
          list.push(arguments[i]);console.log(list);
      }
}}(1,2,3,4));
it works that way (not fond of having console.log in the same line)
Evan Davis
@davisec52
Feb 27 2015 18:24
moment
Cristián Berríos
@crisberrios
Feb 27 2015 18:26
@Dadsaster arguments.length is also useful
Evan Davis
@davisec52
Feb 27 2015 18:26
function destroyer(arr) {
  var list = [];
  var i;
  for(i in Object.keys(arguments)) {
      if(i > 0) {
          list.push(arguments[i]);
      }
  }
  var result = arr.filter(function(a) {
      if(a !== arguments[i]) {
          return a;
      }
  });

  return result;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Still not returning [1, 1]
Cristián Berríos
@crisberrios
Feb 27 2015 18:28
well, you now have your filter list in the list variable
but aren't using it anywhere else in the function
Evan Davis
@davisec52
Feb 27 2015 18:29
I thought I was comparing a with arguments[i]
Cristián Berríos
@crisberrios
Feb 27 2015 18:31
but what's on arguments[i]
and how does filter work?
Evan Davis
@davisec52
Feb 27 2015 18:32
The output is supposed to be an array excluding 2,3 right?
Cristián Berríos
@crisberrios
Feb 27 2015 18:33
right
Evan Davis
@davisec52
Feb 27 2015 18:35
I thought the filter would be comparing each element a to see if it equals arguments[i] and if not, returning that value.
Cristián Berríos
@crisberrios
Feb 27 2015 18:35
nope, check the documentation mdn.io/filter
also, arguments[i] depends on i
which has to be set somewhere
When you say arguments[i], it doesn't automatically iterate over all the keys of arguments
just over the value located at "i" key of arguments
so using i or [i] anywhere doesn't automatically makes it an iteration.
Evan Davis
@davisec52
Feb 27 2015 18:39
ok. Not sure how to fix it.
Ashley Drake
@aldraco
Feb 27 2015 19:04
hm, anybody have their computer lock up on the finders keepers bonfire? usually when it's a stack overflow or something it will tell me, so I'm not sure what's going on.
Oliver
@Dadsaster
Feb 27 2015 19:39
run the code somewhere else like repl.it and see if it hangs
Ashley Drake
@aldraco
Feb 27 2015 19:44
i got it to work. not sure what happened ... oh well :)
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 19:47
I'm a little confused about this make a person challenge.
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 20:37
Can anyone help?
Cristián Berríos
@crisberrios
Feb 27 2015 20:42
sure
which challenge is that?
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 20:43
Cristián Berríos
@crisberrios
Feb 27 2015 20:44
ok
where are you stuck?
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 20:45
I have no idea what I'm supposed to do
I can use an object constructor
but I don't know what this thing wants.
Cristián Berríos
@crisberrios
Feb 27 2015 20:46
well, for this challenge, Person is a constructor function
and if you look at what "more information" shows
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 20:46
it looks like I'm supposed to put functions inside the constructor.
Cristián Berríos
@crisberrios
Feb 27 2015 20:46
it will call different methods on the object instance
yes
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 20:47
Ok, I got as much.
var Person = function(firstAndLast) {
 this.getFullName = function(){
    return firstAndLast;
  };
};

var bob = new Person('Bob Ross');
bob.getFullName();
but still not sure
Ashley Drake
@aldraco
Feb 27 2015 20:47
just want to make sure i'm understanding symmetric difference -
Cristián Berríos
@crisberrios
Feb 27 2015 20:48
well, the function is ok, but since it's a constructor
the methods won't be used on the function, but the object instance
at this point, a call to new Person('Bob Ross'); is not returning anything
Ashley Drake
@aldraco
Feb 27 2015 20:49
some of the tests return values that are repeated in all three arguments, etc. I would think they would not be included. Is thinking about it in terms of the total occurrences of each number being odd or even a good start?
Cristián Berríos
@crisberrios
Feb 27 2015 20:49
sure?
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 20:49
@aldraco Will probably need to ask @terakilobyte about that.
@crisberrios I got that.
Cristián Berríos
@crisberrios
Feb 27 2015 20:49
@aldraco nothing to do with odd or even
[1,1,1,1],[2,3],[2,3] should return [1] since it's also a unique entry per value
Danny Fritz
@dannyfritz
Feb 27 2015 20:51
is this the symmetric difference one?
Cristián Berríos
@crisberrios
Feb 27 2015 20:51
yes
Danny Fritz
@dannyfritz
Feb 27 2015 20:51
i would definitely look at thsi venn diagram http://en.wikipedia.org/wiki/Symmetric_difference#Properties
Ashley Drake
@aldraco
Feb 27 2015 20:53
hm. ok. it's easier to understand for two sets
it's three that's tripping me up
@dannyfritz the diagram and commutative property comment were helpful ... thanks. i'll try that now
thanks @crisberrios
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 20:57
@crisberrios still unsure what I'm supposed to do here.
is bob.getFullName(); meant to call a function?
Cristián Berríos
@crisberrios
Feb 27 2015 20:58
yes
but a function of bob
not "Person"
since Person is just called once to build a bob object
you should search a bit for the construction pattern
constructor pattern
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 20:59
I did.
Cristián Berríos
@crisberrios
Feb 27 2015 20:59
can you paste an example of a constructor here?
It will make it clear
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 20:59
function person(first, last, age, eyecolor) {
    this.firstName = first;
    this.lastName = last;
    this.age = age;
    this.eyeColor = eyecolor;
}
var myFather = new person("John", "Doe", 50, "blue");
var myMother = new person("Sally", "Rally", 48, "green");
Cristián Berríos
@crisberrios
Feb 27 2015 21:00
ok
in that case, object properties are only strings and numbes
numbers
but they can also be objects or functions
and if you use a function as a property
it becomes a method
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 21:01
So what'd I miss? because it looks like that's what I put in it
this.getFullName = function(){
    return firstAndLast;
  };
Cristián Berríos
@crisberrios
Feb 27 2015 21:02
you miss storing the passed parameters
as object properties
and call the local properties from the functions
since the argument only exists when constructing the object
but not on the object instance
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 21:03
var Person = function(firstAndLast) {
 var fullName = firstAndLast;
 this.getFullName = function(){
    return firstAndLast;
  };
};

var bob = new Person('Bob Ross');
bob.getFullName();
so I set a variable?
Cristián Berríos
@crisberrios
Feb 27 2015 21:04
@dannyfritz I'll have to read a little more on symmetric difference. I built a function that passed all the tests, but according to that link there's more to it.
Danny Fritz
@dannyfritz
Feb 27 2015 21:04
yeah, i was wondering about what would happen with 4 inputs
would the center be excluded for 4 inputs?
Cristián Berríos
@crisberrios
Feb 27 2015 21:06
@piecedigital if you use var xx = something in a construction function, you start diving in the land of closures and data privacy, which is good, but for this example, a simple this.firstAndLast = firstAndLast is enough
Danny Fritz
@dannyfritz
Feb 27 2015 21:11
@crisberrios doesn't the bonfire require the closure?
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 21:12
This message was deleted
var Person = function(firstAndLast) {
 this.firstAndLast = firstAndLast;
 this.getFullName = function(){
    return firstAndLast;
  };
};

var bob = new Person('Bob Ross');
bob.getFullName();
Still not clicking, apparently.
Danny Fritz
@dannyfritz
Feb 27 2015 21:12
@piecedigital your function is returning the argument firstAndLast rather than this.firstAndLast
Hannan Ali
@abdulhannanali
Feb 27 2015 21:13
Are there 35 total bonfires?
Cristián Berríos
@crisberrios
Feb 27 2015 21:14
I think there are 35 for now, check the json file in FCC repo
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 21:14
@dannyfritz Still not doing it.
Hannan Ali
@abdulhannanali
Feb 27 2015 21:14
@crisberrios Thanks!
Evan Davis
@davisec52
Feb 27 2015 21:20
After much trial and error I have a solution for the Destroyer challenge that has
passed the Bonfire testing algo. (Yay.) However, I don't really understand why the
filter works.

function destroyer(arr) {
  var list = [];
  var i;
  for(i in Object.keys(arguments)) {
      if(i > 0) {
          list.push(arguments[i]);
      }
  }

  var result = arr.filter(function(a) {
      if(arr.indexOf(i) === list.indexOf(a)) {
          return a;
      }


  });

  return result;
}
destroyer([1, 2, 3, 5, 1, 2, 3, 7], 2, 3);
Cristián Berríos
@crisberrios
Feb 27 2015 21:25
that shouldn't work @davisec52
I think you made the tests explode or something
Evan Davis
@davisec52
Feb 27 2015 21:26
@crisberrios Ok, but the Bonfire sandbox did give me a pass
Cristián Berríos
@crisberrios
Feb 27 2015 21:26
function inside filter should return true or false
Evan Davis
@davisec52
Feb 27 2015 21:26
Help me out here, if it shouldn't work, help me connect the dots.
Cristián Berríos
@crisberrios
Feb 27 2015 21:26
ok... you have a list variable
with the items you want to remove
and arr which is the collection on where to search
Evan Davis
@davisec52
Feb 27 2015 21:27
@crisberrios I just ran the test again copying from the sample above and it still passed.A bug in the system?
@crisberrios continue
Cristián Berríos
@crisberrios
Feb 27 2015 21:28
so, when using filter, you pass each item from arr
one at a time
to the function
and you want to check if that item is in the filter list
Evan Davis
@davisec52
Feb 27 2015 21:28
ok
Cristián Berríos
@crisberrios
Feb 27 2015 21:29
so, how would you express "check if item A is in array B" ?
?
or... "Where in B is A"
Evan Davis
@davisec52
Feb 27 2015 21:31
if(arrayB[i] === A)
?
Cristián Berríos
@crisberrios
Feb 27 2015 21:32
that would only be asking (is A in the i position of B?)
Evan Davis
@davisec52
Feb 27 2015 21:32
I thought that would be asking is an element of arrayB is equal to A
Cristián Berríos
@crisberrios
Feb 27 2015 21:32
Where in B is A ===> B.indexOf(A);
if A is inside B, the return value will be greater or equal than zero
if A is not inside B, it will return -1
from that, you can either return false (don't add the item to the filtered array)
or return true (add the item to the filtered array)
Danny Fritz
@dannyfritz
Feb 27 2015 21:35
here are some simple examples of Array.prototype.filter to study http://jsbin.com/tevubawiwu/1/edit?js,console
Evan Davis
@davisec52
Feb 27 2015 21:35
I tried a filter using .indexOf(item) >= 0 but it only returned the values to be excluded.
Gregory Scheerlinck
@greg-js
Feb 27 2015 21:36
Right, I'm stumped, has anyone doen the orbital period bonfire?
Danny Fritz
@dannyfritz
Feb 27 2015 21:36
@wdgreg i've done all the bonfires. :) are your values close?
Cristián Berríos
@crisberrios
Feb 27 2015 21:36
@davisec52 because you were returning the actual value, and even -1 is a "true" value
Gregory Scheerlinck
@greg-js
Feb 27 2015 21:37
Yeah, I actually did get it by adding 6367.5 in the formula, but I don't understand why, I just tried different values until I got the right answer (starting with 6371.009, which was very close)
Cristián Berríos
@crisberrios
Feb 27 2015 21:37
@dannyfritz @wdgreg I think that instructions on orbital period aren't 100% clear and also it's a little opinionated on the constants.
Evan Davis
@davisec52
Feb 27 2015 21:37
@crisberrios Ok
Cristián Berríos
@crisberrios
Feb 27 2015 21:37
@wdgreg use earth radius from Wolfram Alpha
Danny Fritz
@dannyfritz
Feb 27 2015 21:38
yeah, i fudged the values around until it liked what i calculated
Gregory Scheerlinck
@greg-js
Feb 27 2015 21:38
@crisberrios DOH of course! it says right in the instructions to use the value from Wolfram Alpha and yeah you're right, it's there
I could have sworn I looked it up on there before and tried that value and it was off by more than the value from wiki but I guess I must have made a typo or something
thanks this explains a lot :)
@dannyfritz since you've done them all, can you tell me around how many are left after the orbital period one? I'd like to finish them later tonight but only if it can be done in an hour or two
Cristián Berríos
@crisberrios
Feb 27 2015 21:44
I think 2 more
maybe 3
Gregory Scheerlinck
@greg-js
Feb 27 2015 21:44
alright that should be doable, thanks :)
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 21:45
I'm still not getting this thing
Cristián Berríos
@crisberrios
Feb 27 2015 21:52
want to pair?
looks like 3 challenges
Julie Myers
@BlueOceanView
Feb 27 2015 22:14
Hi Everyone.
Gregory Scheerlinck
@greg-js
Feb 27 2015 22:14
Cool, thanks :)
Julie Myers
@BlueOceanView
Feb 27 2015 22:14
Does anyone happen to know how to send an email using node.js?
I've been reading up on NodeMailer.
Cristián Berríos
@crisberrios
Feb 27 2015 22:19
I've only used nodemailer
Julie Myers
@BlueOceanView
Feb 27 2015 22:21
@crisberrios I assume you really like it?
Here is an article I found. Seems to be good. http://codeforgeek.com/2014/07/send-e-mail-node-js/
Cristián Berríos
@crisberrios
Feb 27 2015 22:22
no, I only used it in one project
I mean
it's simple enough for mailing simple stuff
Julie Myers
@BlueOceanView
Feb 27 2015 22:24
Simple stuff is all I need. Thanks. I think I'll use the coding in the article.
Cristián Berríos
@crisberrios
Feb 27 2015 22:24
start with the docs
always the 1st thing to do :D
Julie Myers
@BlueOceanView
Feb 27 2015 22:25
good idea
Evan Davis
@davisec52
Feb 27 2015 22:34
@crisberrios The solution I posted produces correct results in repli.it and in the chrome js console. It would appear that it is a correct solution . . . possibly for reasons that are not immediately apparent,
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 22:34
var Person = function(firstAndLast) {  
  var self = this;

  this.getFullName = function(newFullName){
    return firstAndLast;
  };
  this.getFirstName = function(){
    self.firstName = firstAndLast.split(" ").shift();
    return self.firstName;
  };
  this.getLastName = function(){
    self.lastName = firstAndLast.split(" ").pop();
    return self.lastName;
  };
  this.setFullName = function(newFullName){
    return newFullName;
  };
  this.setFirstName = function(newFirstName){
    return newFirstName;
  };
  this.setLastName = function(newLastName){
    return newLastName;
  };
};

var bob = new Person('Bob Ross');
bob.setFullName('bobo');
All I need to do now is get the set functions to work.
Cristián Berríos
@crisberrios
Feb 27 2015 22:36
@davisec52 the function works, but the code isn't intended to do what it's supposed to do
var result = arr.filter(function(a) {
      if(arr.indexOf(i) === list.indexOf(a)) {
          return a;
      }
Evan Davis
@davisec52
Feb 27 2015 22:37
@crisberrios ok, but it does produce the correct results.
Cristián Berríos
@crisberrios
Feb 27 2015 22:37
arr.indexOf(i) probably returns -1 as it's not found
Evan Davis
@davisec52
Feb 27 2015 22:37
yes,
as well as list.indexOf(a)
both produce -1
Cristián Berríos
@crisberrios
Feb 27 2015 22:38
and if list.indexOf(a) which is the right way to find the item in the list
no
list.indexOf(a) might produce a valid value
and if it does, then removing it from the original array
you won't return anything
so the return value is undefinde
undefined
which is also "falsy"
and if it's not found, you return the value
and any value, except 0, is "truthy"
so the function kind of works
Evan Davis
@davisec52
Feb 27 2015 22:40
kind of cool, in a weird way
Danny Fritz
@dannyfritz
Feb 27 2015 22:41
well, if i is used after a for using i, i will be equal to the last value of the for until the scope is gc'ed.
Cristián Berríos
@crisberrios
Feb 27 2015 22:41
since you are using the number as the return value
Evan Davis
@davisec52
Feb 27 2015 22:41
@dannyfritz I'm sorry, I don't really immediately understand what you are saying.
Cristián Berríos
@crisberrios
Feb 27 2015 22:41
if you add 0 to the origin list
the function will fail
Evan Davis
@davisec52
Feb 27 2015 22:42
ok
right, it does not return 0
Danny Fritz
@dannyfritz
Feb 27 2015 22:43
because 0 is a falsey value in JS.
Evan Davis
@davisec52
Feb 27 2015 22:43
@dannyfritz ok, so it does not read it as a number
@crisberrios by the way, the link opens a blank page.
Cristián Berríos
@crisberrios
Feb 27 2015 22:44
it does?
Danny Fritz
@dannyfritz
Feb 27 2015 22:44
filter takes whatever is returned and evaluates it as true or false
Evan Davis
@davisec52
Feb 27 2015 22:44
@crisberrios for me it does. I've tried opening the link several times.
@dannyfritz that works
Cristián Berríos
@crisberrios
Feb 27 2015 22:44
Danny Fritz
@dannyfritz
Feb 27 2015 22:45
@crisberrios click the share button at the top, and check JS and Console to get a link that is easy to open
Cristián Berríos
@crisberrios
Feb 27 2015 22:45
I did that
but copied the link at the top
:chicken:
Danny Fritz
@dannyfritz
Feb 27 2015 22:46
:sparkle:
worst emoji ever
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 22:50
I almost got it but I'm missing 3, the set functions
This message was deleted
never mind, I got it.
var Person = function(firstAndLast) {  
  var self = this;
  this.getFullName = function(val){
    return firstAndLast;
  };
  this.getFirstName = function(){
    self.firstName = firstAndLast.split(" ").shift();
    return self.firstName;
  };
  this.getLastName = function(){
    self.lastName = firstAndLast.split(" ").pop();
    return self.lastName;
  };
  this.setFullName = function(newFullName){
    firstAndLast = newFullName;
    return;
  };
  this.setFirstName = function(newFirstName){
    firstAndLast = newFirstName;
    return;
  };
  this.setLastName = function(newLastName){
    firstAndLast = newLastName;
    return;
  };
};

var bob = new Person('Bob Ross');
bob.getFullName('bobo');
Cristián Berríos
@crisberrios
Feb 27 2015 23:24
@piecedigital I think you are kind of missing the point of setters and getters
since you pass any argument to firstAndLast
if you call bob.setLastName("john");
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 23:25
@crisberrios Talking it over with someone else we figured the test cases are flawed.
Cristián Berríos
@crisberrios
Feb 27 2015 23:25
it seems so
but your function shouldn't pass the tests
Darryl Dixon - Piece Digital
@piecedigital
Feb 27 2015 23:27
Yeah, I can see how.
Hannan Ali
@abdulhannanali
Feb 27 2015 23:44
Will somebody check it out if pairing works by clicking this link
Anyone here?