These are chat archives for FreeCodeCamp/Help

3rd
Jan 2015
MychaelZ
@MychaelZ
Jan 03 2015 00:43
hey im trying to rewrite javascipts pop method
i saw the code from the V8 engine but they were using functions that im not familiar with
i wanted to know if there was a simple way to write it
the only thing i am stuck on is mutating the original array
for ex
var arr = [1,2,3];
arr.pop();
console.log(arr)
// output [1,2]
how do i get it to remove the element from the arr variable
Darryl Dixon - Piece Digital
@piecedigital
Jan 03 2015 00:48
What are you trying to remove?
.pop() removes the last item in an array, .shift() removes the first
Ben Stoltz
@benstoltz
Jan 03 2015 00:49
He’s trying to re-create the pop method from JS.
As a learning exercise.
MychaelZ
@MychaelZ
Jan 03 2015 00:50
yes
i am trying to do it by using Array's prototype
i think making a simple function would work but i rather use the prototype
Darryl Dixon - Piece Digital
@piecedigital
Jan 03 2015 00:53
So.. you're trying to create a function like .pop() but not using pop
the only thing I can think of would to use splice
MychaelZ
@MychaelZ
Jan 03 2015 00:54
yes
but i need to redefine the arr variable as seen in the exsmple above
Christopher Hutchinson
@cshutchinson
Jan 03 2015 00:55
does anyone remember the trick to adding the :hover event in chrome devtools to the events lists? I've watched the video countless times; selected the events class, but just can't get it to work
section 1.2
last item
Darryl Dixon - Piece Digital
@piecedigital
Jan 03 2015 00:56
@cshutchinson You can add an event listener
Christopher Hutchinson
@cshutchinson
Jan 03 2015 00:57
ty @piecedigital
Dominic Desimini
@trisell
Jan 03 2015 01:16
For those of you far enough along. Here is a very good piece about node.js development mistakes. https://www.airpair.com/node.js/posts/top-10-mistakes-node-developers-make
Nathan
@terakilobyte
Jan 03 2015 01:17
this also is a great node resource, an inside look at what successful node apps look like on the inside
Justin Rogers
@yaskyj
Jan 03 2015 01:34
@MychaelZ Can you call the function with call or apply to change the 'this' value?
MychaelZ
@MychaelZ
Jan 03 2015 01:35
thats actualy a great idea
MychaelZ
@MychaelZ
Jan 03 2015 01:42
justin if this works u are awesome!
Justin Rogers
@yaskyj
Jan 03 2015 01:51
@MychaelZ You figure out map with arrays concat?
Nathan
@terakilobyte
Jan 03 2015 01:53
slice might be a simple option
little things like this make me miss pointers
Justin Rogers
@yaskyj
Jan 03 2015 01:55
@terakilobyte I'm guessing that's why the source is in C++.
Nathan
@terakilobyte
Jan 03 2015 01:58
could be
I’ve not looked at the source yet
MychaelZ
@MychaelZ
Jan 03 2015 02:01
no have not figured it out
im still on pop lol trying to get a better grasp of the apply method
the entire book is excellent, I suggest reading it and playing as you have time
but that chapter does an excellent job of explaining apply
Dominic Jones
@towwiow
Jan 03 2015 02:13
@terakilobyte & @yaskyj - my second laptop is running super retarded guys. I'm about to download ubuntu onto a thumb drive and boot it up on the other laptop
would I be able to get the files from the laptop if I'm running in ubuntu?
Justin Rogers
@yaskyj
Jan 03 2015 02:16
@towwiow Do you mean if you change the boot sequence to start in Ubuntu from the flash drive?
Dominic Jones
@towwiow
Jan 03 2015 02:21
yea
I don't think I will be able to
Justin Rogers
@yaskyj
Jan 03 2015 02:52
@towwiow You're just trying to try out Linux, right?
Leonardo Prates
@odran037
Jan 03 2015 04:44
You can have ubuntu access your C: drive. I can't remember if there is a special setup to be able to do this or it automatically mounts the drive. I also can't remember if it only has read permissions or not. But the short answer is yes you can access your drives from other OSes from ubuntu or any linux distro really.
I no longer dual boot so my memory is hazy. I have dedicated machines for OS X and linux.
Ian Yeager
@iyeager2004
Jan 03 2015 06:16
I thought it couldn't mount a typical Windows partition. Just guessing though, I always go whole hog and pull the trigger on a format.
function FirstFactorial(num) { 

  if (num < 0) {
    return -1;
  } else if (num == 0) {
    return 1;
  } else {
    return num * FirstFactorial(num - 1);
  }
}
Any better way to write this?
Nathan
@terakilobyte
Jan 03 2015 06:21
@iyeager2004 why are you checking for < 0?
Ian Yeager
@iyeager2004
Jan 03 2015 06:24
Edge case, in case someone enters a zero.
Nathan
@terakilobyte
Jan 03 2015 06:25
if they enter zero you are returning 1
and -5! is -120
don’t worry about negatives though
Ian Yeager
@iyeager2004
Jan 03 2015 06:27
Wait, -5 returns -1.
That's why I check if it's less than zero.
Sorry, I didn't read your question.
Nathan
@terakilobyte
Jan 03 2015 06:27
I’m saying -5! should equal -120, but don’t worry about negatives
Ian Yeager
@iyeager2004
Jan 03 2015 06:28
I thought the factorial of a negative number was undefined.
Hence the -1.
Nathan
@terakilobyte
Jan 03 2015 06:29
wolfram says otherwise, I had to check myself though
but, consider this
why are you returning 1 if the number is 0?
Ian Yeager
@iyeager2004
Jan 03 2015 06:30
That's the return to get out of the recursion.
Once you hit zero, you're done.
Nathan
@terakilobyte
Jan 03 2015 06:30
what is 1 times 1?
Ian Yeager
@iyeager2004
Jan 03 2015 06:30
No ECMAScript in here. Couldn't tell ya. :)
Why does this pass in Coderbyte than?
Nathan
@terakilobyte
Jan 03 2015 06:31
lol, apologies
because they are giving you only positives I believe
but I’m trying to get at a way to optimize it
I did somethign similar years ago and was shown a better way
0 is < 1
1 * any number won’t change the number
is there a need to create another layer on the stack for any number <2 in your function if you are just goign to return 1 or -1?
Ian Yeager
@iyeager2004
Jan 03 2015 06:33
Hmm.... unlikely. True.
Nathan
@terakilobyte
Jan 03 2015 06:33
imagine
FirstFactorial(2)
Ian Yeager
@iyeager2004
Jan 03 2015 06:34
Should just be 2.
But, you're right, it spawns two layers to get there.
Nathan
@terakilobyte
Jan 03 2015 06:34
2 * FirstFactorial(2 - 1)
…
1 * FirstFactorial(1 - 1)
…
0 -> return 1
1 * 1 = 1 return 1 ->
1 * 2 = 2 return 2
end
Ian Yeager
@iyeager2004
Jan 03 2015 06:35
Right, three, has to get to zero.
Nathan
@terakilobyte
Jan 03 2015 06:36
you can check for end of execution and values you can’t handle more easily and with only one check vs two, and if you were writing a library you’d just publish in the API that FirstFactorial can only accept positive values and it is on the caller to handle sign
Ian Yeager
@iyeager2004
Jan 03 2015 06:37
Right, because this works...
function FirstFactorial(num) { 

if (num == 2) {
    return 2;
  } else {
    return num * FirstFactorial(num - 1);
  }
}
But, if you enter a negative, you still get an error.
Nathan
@terakilobyte
Jan 03 2015 06:37
check for less or equal
otherwise you’ll blow up the process
Ian Yeager
@iyeager2004
Jan 03 2015 06:37
Good plan.
Nathan
@terakilobyte
Jan 03 2015 06:37
if I passed 0 it would continue forever until it consumed all memory allocated and crashed
Ian Yeager
@iyeager2004
Jan 03 2015 06:38
But now passing a negative returns 2.
Nathan
@terakilobyte
Jan 03 2015 06:38
right, generally make your terminator end on on1
< 2
return num < 2 ? 1 : FirstFactorial(num - 1);
does that make sense?
Ian Yeager
@iyeager2004
Jan 03 2015 06:42
No. I haven't seen the ':' operator, is that a tertiary operator in JS?
Nathan
@terakilobyte
Jan 03 2015 06:42
ternary, yep
it’s the equivalent of this
if (num < 2) {
  return 1;
} else {
  return FirstFactorial(num - 1);
}
Ian Yeager
@iyeager2004
Jan 03 2015 06:45
So it should be return num < 2 ? 1 : num * FirstFactorial(num - 1);
right?
Nathan
@terakilobyte
Jan 03 2015 06:45
they are very useful for returns and assignments that are conditional upon the evaluation of a single expression. Be careful not to be tempted to abuse them and put a lot of logic in them as it can make them hard to read. And don’t nest them. It’s possible, but you may get stabbed in the eyes.
Ian Yeager
@iyeager2004
Jan 03 2015 06:45
function FirstFactorial(num) { 
  return num < 2 ? 1 : num * FirstFactorial(num - 1);
}
Nathan
@terakilobyte
Jan 03 2015 06:45
yep
nice and concise. Sorry, very tired
Ian Yeager
@iyeager2004
Jan 03 2015 06:46
That's okay. Me too. I need to wrap it up for the night I think.
Thanks for the help @terakilobyte.
Ian Yeager
@iyeager2004
Jan 03 2015 15:51
Having trouble with the Node.js streams challenge.
It keeps saying that on this code here...
var fs = require('fs');
var file = fs.createReadStream('fruits.txt');

file.on('readable', function() {
  var chunk = null;
  while (null !== (chunk = file.read())) {
    console.log(toString(chunk));
      }  
});
that I'm not calling the toString() on the data that was read.
Nathan
@terakilobyte
Jan 03 2015 15:54
try chunk.toString()
Ian Yeager
@iyeager2004
Jan 03 2015 15:54
D'oh
Thanks
Ian Yeager
@iyeager2004
Jan 03 2015 19:44
I'm working on the express portion of Node.js challenges, specifaclly handling route parameters. Any idea what it doesn't like about this? The error the codeschool gives back is to be sure to write the quote and close the response. Seems like I'm doing both.
app.get('/quotes/:quoteName', function(request, response) {
  response.locals({name: quoteName});
  response.write(quotes[name]);
  response.close();
});
Everyone out to lunch?
GrahamFischer
@GrahamFischer
Jan 03 2015 19:50
It would appear so
Dominic Jones
@towwiow
Jan 03 2015 19:50
sorry bro
I'm not that far along to help out @iyeager2004 :(
Maxim Orlov
@Maximization
Jan 03 2015 19:54
@iyeager2004 do you have a link to codeschool
Dominic Jones
@towwiow
Jan 03 2015 19:56
I'd be more than happy to talk it out with you, see if we can get through it via conversation xD
Ian Yeager
@iyeager2004
Jan 03 2015 19:57
I figured it out. They wanted me to use response.end(quotes[request.params.quoteName]); instead of step by step.
Seems like sometimes they want you to show the individual steps and sometimes they want optimized code.
Maxim Orlov
@Maximization
Jan 03 2015 19:58
codeschool can be very picky at times
Dominic Jones
@towwiow
Jan 03 2015 19:59
yeah - I feel like the tutorials for coding can still use improvements in that area - consistency with the answers it's looking for.
Or a combination of that and clearer problem descriptions
Ian Yeager
@iyeager2004
Jan 03 2015 20:02
Some sort of CI server that verifies the response rather than just what's written, but I get that they want to enforce well-written code.
Leonardo Prates
@odran037
Jan 03 2015 21:44
Working on challenge #14 - Discover Chrome Dev Tools. I'm on section 3.1 Working with the Console. "Find the element with an id of "events" and print it to the console." I'm not sure how I would do this. From what I understand I'd have to use jQuery, if thats the case I'm having a blank putting together the syntax for console.log. If not than I'm way off. Any ideas?
Jonathan
@jonathanzamudio
Jan 03 2015 21:45
the sintax is the same you would use with jquery in a regular script
eg: $('someselector').someMethod();
Leonardo Prates
@odran037
Jan 03 2015 21:49
Thank you. I give it a shot.
I'll*
Alex Hazel
@metalhaze
Jan 03 2015 21:49
console.log(JQuery selector here) you can log a string, a variable, or JQuery selector, ect..
Leonardo Prates
@odran037
Jan 03 2015 21:52
Thank you fellas. Got it to work with your tips. I don't know why I was over complicating this in my head.
Dominic Jones
@towwiow
Jan 03 2015 23:13
anyone familiar with ubuntu online?
Jonathan
@jonathanzamudio
Jan 03 2015 23:36
oh, I didn't know about it, looks pretty neat