These are chat archives for FreeCodeCamp/Help

25th
Feb 2015
Matthew Harames
@Harames
Feb 25 2015 00:46 UTC
@terakilobyte Nice, I was thinking it was weird that it didn't save it, but now I know better.
Oliver
@Dadsaster
Feb 25 2015 02:40 UTC
@terakilobyte - thanks for the code buff a while back.
Nathan
@terakilobyte
Feb 25 2015 06:39 UTC
@PKMNinja I think of things ;)
the plan was to always make them visible
@Dadsaster np, if you can avoid hardcoding values you always should
the nice thing about the method I posted is it could work with unicode or any other system
Jon Lucas
@jonslucas
Feb 25 2015 12:52 UTC
@terakilobyte Why did you make the escapeHtml object use functions? Is that better than just setting '&':'&apm;'?
*'&':'&' - - can't spell; too early
Szajbob
@Szajbob
Feb 25 2015 14:15 UTC
hi all!
Jon Lucas
@jonslucas
Feb 25 2015 14:15 UTC
@Szajbob Hi!
What am I suppose to do in this one?
Cristián Berríos
@crisberrios
Feb 25 2015 14:16 UTC
hey
Szajbob
@Szajbob
Feb 25 2015 14:16 UTC
@AmmarAliShah write a script that does this
Cristián Berríos
@crisberrios
Feb 25 2015 14:16 UTC
@AmmarAliShah 5 becomes 1*2*3*4*5
Jon Lucas
@jonslucas
Feb 25 2015 14:17 UTC
@AmmarAliShah The more information button is helpful on that one
Ammar Ali Shah
@AmmarAliShah
Feb 25 2015 14:17 UTC
@jonslucas yeah just though of reading that lol
Szajbob
@Szajbob
Feb 25 2015 14:17 UTC
I have a problem with this bonfire
Jon Lucas
@jonslucas
Feb 25 2015 14:18 UTC
@Szajbob what have you got so far?
Szajbob
@Szajbob
Feb 25 2015 14:18 UTC
I think I almost nailed it, here's my code
Ammar Ali Shah
@AmmarAliShah
Feb 25 2015 14:18 UTC
@crisberrios 10 into 123456789*10
Cristián Berríos
@crisberrios
Feb 25 2015 14:18 UTC
yes @AmmarAliShah
Szajbob
@Szajbob
Feb 25 2015 14:18 UTC

function chunk(arr, size) {
var array = [];
var finalArray = [];
for (var i = 0; i < size; i++) {
for (var y = 0; y < size; y++) {
array[y] = arr[y+i];
console.log(array);
}
finalArray.push(array);
console.log(finalArray);

}
return finalArray;
}

chunk(['a', 'b', 'c', 'd'], 2);

Cristián Berríos
@crisberrios
Feb 25 2015 14:19 UTC
add backticks in lines before and after code
```
Szajbob
@Szajbob
Feb 25 2015 14:19 UTC
it works fine the first time, but on second iteration of for loop with 'i' parameter, it adds the new array as a first one, and second becomes circular object array (?)
Cristián Berríos
@crisberrios
Feb 25 2015 14:19 UTC
so we can see the format
Szajbob
@Szajbob
Feb 25 2015 14:21 UTC
function chunk(arr, size) {
var array = [];
var finalArray = [];
for (var i = 0; i < size; i++) {
for (var y = 0; y < size; y++) {
array[y] = arr[y+i];
console.log(array);
}
finalArray.push(array);
console.log(finalArray);

}
return finalArray;
}

chunk(['a', 'b', 'c', 'd'], 2);
almost! :smile:
function chunk(arr, size) {
  var array = [];
  var finalArray = [];
  for (var i = 0; i < size; i++) {
    for (var y = 0; y < size; y++) {
      array[y] = arr[y+i];
      console.log(array);
    }
  finalArray.push(array);
  console.log(finalArray);

  }
  return finalArray;
}

chunk(['a', 'b', 'c', 'd'], 2);
ok, that should be fine enough
so, as I wrote, after first iteration of for loop with 'i' parameter the finalArray looks good, it is an array which contains an array inside with a and b
Jon Lucas
@jonslucas
Feb 25 2015 14:23 UTC
I added console.log(i, y, array, arr[y+i], arr[i], arr[y]); before your array[y]... which showed that your for loops might need to be reworked
Cristián Berríos
@crisberrios
Feb 25 2015 14:24 UTC
hmm
Szajbob
@Szajbob
Feb 25 2015 14:24 UTC
thank you very much! how can I access what you've added?
Cristián Berríos
@crisberrios
Feb 25 2015 14:24 UTC
@Szajbob
I think your loops don't make much sense
I understand that you are rearranging the array
moving the positions from [i+1] into [i]
Jon Lucas
@jonslucas
Feb 25 2015 14:25 UTC
@Szajbob copy/paste? I meant I added it on my local copy
so I could inspect the values being address
Szajbob
@Szajbob
Feb 25 2015 14:25 UTC
ok :D thank you! doing it now!
Cristián Berríos
@crisberrios
Feb 25 2015 14:25 UTC
but you are kind of overthinking the problem
If you look at the instructions
Szajbob
@Szajbob
Feb 25 2015 14:26 UTC
I knew there is an easier way!
Cristián Berríos
@crisberrios
Feb 25 2015 14:26 UTC
and the example
you are being asked to "group chunks" of "an array"
so you should start by looking at the array methods
go to mdn.io/array
and check slice and splice methods
maybe shift too
to see if they make sense to you
Jon Lucas
@jonslucas
Feb 25 2015 14:27 UTC
@crisberrios Good call on slice/splice
Szajbob
@Szajbob
Feb 25 2015 14:28 UTC
ok, thank you! I start toying with this right away!
cerissa
@cerissa
Feb 25 2015 14:34 UTC
how would i get an icon to scroll down to the bottom part of the page, with jquery, i thought scrollTo would have worked but it didnt
Jon Lucas
@jonslucas
Feb 25 2015 14:42 UTC
@cerissa Like it follows you as you scroll down? Or as a shortcut to the bottom of the page?
Cristián Berríos
@crisberrios
Feb 25 2015 14:42 UTC
do you have the code that didn't work?
Szajbob
@Szajbob
Feb 25 2015 14:43 UTC
just came back for a momment to thank you @crisberrios and @jonslucas ! splice() made it a really quick work :smile:
cerissa
@cerissa
Feb 25 2015 14:43 UTC
no scrollto was bad idea, i want it to jump to the bottom,
@crisberrios no i deleted it a few days ago
Jon Lucas
@jonslucas
Feb 25 2015 14:43 UTC
I defer to @crisberrios
Cristián Berríos
@crisberrios
Feb 25 2015 14:43 UTC
I haven't used it but I see many examples on using scrollTop
combined with animate
cerissa
@cerissa
Feb 25 2015 14:45 UTC
ok ill try that thanks
Oliver
@Dadsaster
Feb 25 2015 14:52 UTC
This message was deleted
Cristián Berríos
@crisberrios
Feb 25 2015 14:52 UTC
01
Jon Lucas
@jonslucas
Feb 25 2015 14:53 UTC
@crisberrios Just looking over some of the other Array methods - Is .filter() just a specific form of .map()?
Cristián Berríos
@crisberrios
Feb 25 2015 14:53 UTC
nope
because map always returns an array of the same size as the original
Ryan Malm
@Rybar
Feb 25 2015 14:54 UTC
or 15 minutes of reading at MDN?
Cristián Berríos
@crisberrios
Feb 25 2015 14:54 UTC
and entries are modified
Jon Lucas
@jonslucas
Feb 25 2015 14:54 UTC
gotcha
Cristián Berríos
@crisberrios
Feb 25 2015 14:54 UTC
but filter returns only filtered entries
without modification
Oliver
@Dadsaster
Feb 25 2015 14:55 UTC
I think map also returns a new array whereas filter doesn't but I could be incorrect
Cristián Berríos
@crisberrios
Feb 25 2015 14:55 UTC
it does also return a new array
only splice modifies the original
Jon Lucas
@jonslucas
Feb 25 2015 14:55 UTC
Looks like they both return new arrays
Cristián Berríos
@crisberrios
Feb 25 2015 14:55 UTC
well, and push/pop shift/unshift
Oliver
@Dadsaster
Feb 25 2015 14:56 UTC
@crisberrios 7 am and already learning new stuff
Jon Lucas
@jonslucas
Feb 25 2015 14:57 UTC
Yeah, I need to spend some more time with the docs, for sure
I don't think I used many, if any of the iterator methods for arrays when I solved the challenges/bonfires
cerissa
@cerissa
Feb 25 2015 15:01 UTC
ok another question, probably stupid but how did you get your work you have done onto your portfolio? for the life of me i cant figure out how.
Cristián Berríos
@crisberrios
Feb 25 2015 15:04 UTC
that's for me? I don't even have a portfolio yet :(
Jon Lucas
@jonslucas
Feb 25 2015 15:09 UTC
Technically, don't all FCC users have a portfolio?
-.- that shouldn't be a link....
Cristián Berríos
@crisberrios
Feb 25 2015 15:11 UTC
that's only a profile
Jon Lucas
@jonslucas
Feb 25 2015 15:11 UTC
Well, it's labeled as 'portfolio'
Cristián Berríos
@crisberrios
Feb 25 2015 15:12 UTC
in any case, I think @cerissa means a real portfolio
I'll have to start working on it as soon as we finish our 1st nonprofit
Jon Lucas
@jonslucas
Feb 25 2015 15:12 UTC
Mayhaps
Cristián Berríos
@crisberrios
Feb 25 2015 15:13 UTC
hopefully this week.
cerissa
@cerissa
Feb 25 2015 15:19 UTC
@jonslucas yes i mean a real portfolio
Jon Lucas
@jonslucas
Feb 25 2015 15:20 UTC
@cerissa Then, I'll admit, I really don't know. Sorry
cerissa
@cerissa
Feb 25 2015 15:21 UTC
its ok, i can wait, i have the other things on my portfolio done well i will probably tinker with it a ton.
i can work on some of the other stuff
i have a jsgame that i did for a udemy course, i gave up trying to figure out how to make it have a high score, i might actually redo that game with having a high score in mind
Jon Lucas
@jonslucas
Feb 25 2015 15:24 UTC
High score as in persistent data storage?
cerissa
@cerissa
Feb 25 2015 15:25 UTC
well its not really a high score its more like fastest time,
and i have a few other changes to make
http://codepen.io/cerissa/pen/vEpRQM here is the old version, well soon to be old version
Jon Lucas
@jonslucas
Feb 25 2015 15:29 UTC
Ahh, now I see what you mean about the high score
cerissa
@cerissa
Feb 25 2015 15:30 UTC
yea,
it was a first for me with js, i dont think i even used jquery as i hadnt learned it yet, i might have, i have to check, so now im going to go make it better
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:03 UTC
Has anyone here finished the Map the Debris bonfire challenge?
Jon Lucas
@jonslucas
Feb 25 2015 16:05 UTC
@chrisdziewa Yeah, but I had to fudge the math a little
I'm still not sure what values they used for the test cases
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:06 UTC
Yeah I don't understand the equation necessary to change the altitude. It went from programming problems straight to a physics problem.
Jon Lucas
@jonslucas
Feb 25 2015 16:06 UTC
I could get within 8 at my closest attempt before I solved it
basically, I used Keplar's Third Law formula
Did you check out the wikipedia page?
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:09 UTC
I did but there are so many different things on there I don't really know what to do.
I've tried some of the equations but just must not get it.
Jon Lucas
@jonslucas
Feb 25 2015 16:09 UTC
I've got to step away for a moment, but you should post what you have and we can take a look at it
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:15 UTC
I don't have any of the equation implemented. I just have tried it with a calculator, furthering my confusion as to what I actually need to use in the equation. The easy part is replacing the existing property with a new one.
Serhii Borovskyi
@serhiicss
Feb 25 2015 16:16 UTC
http://regexone.com/lesson/3 Can anyone help me with RegEX please?
Germaine Pannell
@germainep
Feb 25 2015 16:18 UTC
@serhiicss what’s up
Darryl Dixon - Piece Digital
@piecedigital
Feb 25 2015 16:19 UTC
@serhiicss First letters. Same as their example.
Serhii Borovskyi
@serhiicss
Feb 25 2015 16:19 UTC
yeah I dont know how to skip the other 3
Darryl Dixon - Piece Digital
@piecedigital
Feb 25 2015 16:20 UTC
You only need to match the first letter.
Danny Fritz
@dannyfritz
Feb 25 2015 16:20 UTC
you need to select either based on letters or not letters
the explanation above about []'s tells you about selecting from a set of characters
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:21 UTC
@serhiicss if you wanted to select words that start with a,b, or c you could use this
[abc]
Serhii Borovskyi
@serhiicss
Feb 25 2015 16:21 UTC
Ah I got it
lol
Thanks!
Danny Fritz
@dannyfritz
Feb 25 2015 16:22 UTC
@chrisdziewa kind of. you mean if you wanted to select characters a b or c
Jon Lucas
@jonslucas
Feb 25 2015 16:22 UTC
I think the Regex notes on the side are kind of a cheat sheet for what they want you to learn about, if I remember correctly
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:22 UTC
Sorry that's what I meant.
Jon Lucas
@jonslucas
Feb 25 2015 16:23 UTC
@chrisdziewa What is the equation you are using for M-t-D?
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:23 UTC
@dannyfritz
[abc][\w]+
@jonslucas that's the thing I don't know what I'm supposed to use ha.
Danny Fritz
@dannyfritz
Feb 25 2015 16:25 UTC
still not quite @chrisdziewa that would match on danny too
\b[abc][\w]+
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:28 UTC
Well I wanted to be strict and test the whole string where there was the possibility of that case I would probably do:
^[abc][\w]+$
Danny Fritz
@dannyfritz
Feb 25 2015 16:28 UTC
now it isn't words, but lines. :P
use \b
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:30 UTC
But in practice most of the time I would be using a regex on something like a user form, so I would want the whole string.
I can see \b as being good for scraping data
Danny Fritz
@dannyfritz
Feb 25 2015 16:31 UTC
yeah, I agree with that.
Jon Lucas
@jonslucas
Feb 25 2015 16:32 UTC
@chrisdziewa So, we are looking for an equation that defines T, orbital period, in terms or the avgAlt. So, I applied the function provided as Keplar's Third law according to the wikipedia page, since everything else can be assumed as a constant aside from the altitude.
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:34 UTC
@jonslucas does that mean I need to follow this equation? Orbital period as a function of central body's density
Jon Lucas
@jonslucas
Feb 25 2015 16:34 UTC
I used the small body orbiting a central body @chrisdziewa
But maybe that's why my calcs were a little off
I actually got help from @dannyfritz on this one. But I don't remember which formula he used.
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:36 UTC
Well that was the first one I tried but I must be using the wrong values for each variable because my answers were way off from what I remember
Jon Lucas
@jonslucas
Feb 25 2015 16:36 UTC
how did you map the vals to the equation?
as in which variable did you assign to which value
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:39 UTC
well would it be M is mass of earth * 9.8 as the gravitational constant (though wouldn't it be different since the object isn't on earth) to get that u looking variable
let me try writing it out here.
Jon Lucas
@jonslucas
Feb 25 2015 16:40 UTC
If you follow the link for standard gravitational parameter, that'll explain that one
I treated that as a constant that I pulled from that page
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:41 UTC
398600.4418?
Jon Lucas
@jonslucas
Feb 25 2015 16:42 UTC
That's what I used, but I think I ended up casting it as an int, dropping the .4418
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:44 UTC
Is the semi major axis the earth's radius plus the altitude?
Jon Lucas
@jonslucas
Feb 25 2015 16:44 UTC
'tis
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:45 UTC
maybe that's what I was missing too.
Jon Lucas
@jonslucas
Feb 25 2015 16:45 UTC
I had to play with the earth's radius value to actually pass this one
Once again, big thanks to @dannyfritz for that minor adjusment
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:46 UTC
Alright, I will try this.
Thanks for the help!
Jon Lucas
@jonslucas
Feb 25 2015 16:47 UTC
You're welcome
that should at least put you in the right ball park
Has anyone here completed the cash register bonfire?
I'm really curious how people dealt with float inaccuracy
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:50 UTC
I'm off by four using the extra decimal places in the gravitational parameter
Jon Lucas
@jonslucas
Feb 25 2015 16:51 UTC
Dang, that was closer than I got on the first test. For me, the greater the avgAlt, the greater the error.
What happens when you drop the decimal? Closer or farther away?
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:52 UTC
farther away
granted this was just the first one
the error should be more on the larger distances
Jon Lucas
@jonslucas
Feb 25 2015 16:53 UTC
Hmm, drop the earth's radius by .5, see what that does for ya
Evan Davis
@davisec52
Feb 25 2015 16:54 UTC

Good morning! just a quick question. In the first sample below, the function does not return results. It wll console.log, but return gives no result. why is there no returned result?

The second sample both returns results and console.logs.

```

function properties(arr) {
arr.filter(function(q) {
for(var prop in q) {
if(q[prop] === 5) {
return prop + q[prop];
}
}

});
//return prop + q[prop];

}
properties([{"a":1, "b": 2}, {"a": 3, "b": 5}, {"a": 1, "b": 2}, {"a": 5, "b": 7}]); "a": 3, "b": 5}, {"a": 1, "b": 2}, {"a": 5, "b": 7}]);


var arr = [{"a":1, "b": 2}, {"a": 3, "b": 5}, {"a": 1, "b": 2}, {"a": 5, "b": 7}];
arr.filter(function(q) {
for(var prop in q) {
if(q[prop] === 5) {
console.log(prop + q[prop]);
return prop + q[prop];
}
}
});

Sorry about the above, It will not let me edit. I will repost and hopefully get the code right.
Chris Dziewa
@chrisdziewa
Feb 25 2015 16:56 UTC
@jonslucas actually I got within .2 of the correct answer using 6367.5km
Evan Davis
@davisec52
Feb 25 2015 16:56 UTC

Good morning! just a quick question. In the first sample below, the function does not return results. It wll console.log, but return gives no result. why is there no returned result?

The second sample both returns results and console.logs.

```

function properties(arr) {
arr.filter(function(q) {
for(var prop in q) {
if(q[prop] === 5) {
return prop + q[prop];
}
}

});
//return prop + q[prop];

}
properties([{"a":1, "b": 2}, {"a": 3, "b": 5}, {"a": 1, "b": 2}, {"a": 5, "b": 7}]); "a": 3, "b": 5}, {"a": 1, "b": 2}, {"a": 5, "b": 7}]);


var arr = [{"a":1, "b": 2}, {"a": 3, "b": 5}, {"a": 1, "b": 2}, {"a": 5, "b": 7}];
arr.filter(function(q) {
for(var prop in q) {
if(q[prop] === 5) {
console.log(prop + q[prop]);
return prop + q[prop];
}
}
});

```

Chris Dziewa
@chrisdziewa
Feb 25 2015 16:57 UTC
@jonslucas instead of Google's 6371
using round that would give me the correct answer
now just have to implement it in code
Evan Davis
@davisec52
Feb 25 2015 16:57 UTC
I apologize for the mess, above. For some reason, I'm unable to delete or edit.
Jon Lucas
@jonslucas
Feb 25 2015 17:02 UTC
@chrisdziewa Awesome!
I don't really like that problem, since the implementation of the switch is quite easy
It's getting the exact value that they are testing for that is so difficult
Which is more an issue of precision than one of coding/algorithms, but that's really just me ranting
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:04 UTC
Yeah I do like Physics but I'm not learning physics
Jon Lucas
@jonslucas
Feb 25 2015 17:04 UTC
lol
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:04 UTC
and I'm not the greatest at it.
Jon Lucas
@jonslucas
Feb 25 2015 17:05 UTC
@davisec52 Looking now
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:05 UTC
I'm fine with computing numbers, but when I see greek letter constants my brain shuts down
Jon Lucas
@jonslucas
Feb 25 2015 17:05 UTC
@chrisdziewa Luckily, I studied a few years of physics, so I was able to parse that one for the most part. I'd still like to see the values they used to come up with the test results
@chrisdziewa I studied ancient greek for about 18 months. So, I feel nostalgia when I see mu like that
love it
Evan Davis
@davisec52
Feb 25 2015 17:07 UTC
@jonslucas thank you. I didn't post it again--I was worried about duplicating the mess.
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:09 UTC
@jonslucas Haha I'm more into French and Russian
If I could learn every language I would though.
Jon Lucas
@jonslucas
Feb 25 2015 17:10 UTC
function properties(arr){
  arr.filter(function(q) {
    for(var prop in q) {
      if(q[prop]===5) {
        console.log(prop +q[prop]);
        return prop+q[prop];
      }
    }
  });
is this right so far?
@davisec52
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:11 UTC
@jonslucas I finished it! Here's my passing solution for Map the Debris:
function getOrbitalPeriod(avgAlt) {
  //2pi * sqrt((6367.5+413.6)^3/398600.4418)
  var radius = 6367.5 + avgAlt;
  var period = 2 * Math.PI * Math.sqrt(Math.pow(radius, 3)/398600.4418);
  return Math.round(period);
}

function orbitalPeriod(arr) {
  var currentObj;
  for (var element in arr) {
     currentObj = arr[element];
     currentObj.orbitalPeriod = getOrbitalPeriod(currentObj.avgAlt);
     delete currentObj.avgAlt;
  }
  return arr;
}

orbitalPeriod([{name : "sputkin", avgAlt : 35873.5553}]);
Jon Lucas
@jonslucas
Feb 25 2015 17:11 UTC
@chrisdziewa Nice! Congrats! That looks much cleaner than my code, iirc
I appreciate the comment line in your getO...func
Evan Davis
@davisec52
Feb 25 2015 17:12 UTC
@jonslucas Yes, that is what I was trying to do.
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:12 UTC
I hate when functions get to be too messy ha
Evan Davis
@davisec52
Feb 25 2015 17:13 UTC
@jonslucas If runs the code if you take the arr.filter statement out of the function shell.
Jon Lucas
@jonslucas
Feb 25 2015 17:13 UTC
right
let me test it to see what's going on there
Evan Davis
@davisec52
Feb 25 2015 17:13 UTC
Thank you!
Jon Lucas
@jonslucas
Feb 25 2015 17:14 UTC
Also, from what I've found, the for( var i in _) loop is, imho, useless
Not as awesome as python's for...in..
Evan Davis
@davisec52
Feb 25 2015 17:17 UTC
@jonslucas I didn't see how to otherwise isolate the values from the properties.
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:18 UTC
@jonslucas I miss that for in loop. Python is so clean too.
Jon Lucas
@jonslucas
Feb 25 2015 17:19 UTC
@chrisdziewa Python is my fav. I've spent the most time with it.
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:22 UTC
I do ruby a lot now, but I do miss Python. Ruby is close though and adds extra flexibility.
I spent a lot of time on Udacity.
I wasn't really experienced enough at the time for the harder courses though.
Jon Lucas
@jonslucas
Feb 25 2015 17:23 UTC
yeah, I've done some Udacity as well
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:23 UTC
Do you use Django then?
Jon Lucas
@jonslucas
Feb 25 2015 17:23 UTC
@davisec52 What exactly are you trying to do with this func?
I've set up Django a couple of times, but that was a year or more ago now
I've also used the jinja templates before as well
Lately, my python experience has been expediting data entry at my job
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:25 UTC
Yeah used jinja a bit in the Udacity Web Dev course. I bet it has! Python is so good for data, though I haven't ever used it for that kind of thing except for in the courses.
Jon Lucas
@jonslucas
Feb 25 2015 17:26 UTC
Yeah, I actually deepened my understanding by a lot doing things outside of those courses
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:26 UTC
It's funny how much things feel so similar between languages and templates and frameworks after a while.
Evan Davis
@davisec52
Feb 25 2015 17:26 UTC
@jonslucas I'm trying to better understand how to identify and iterate over properties and values in objects in arrays. Right now, I just don't understand why the function won't return a result.
Jon Lucas
@jonslucas
Feb 25 2015 17:26 UTC
I guess because I had to come up with all the steps myself
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:26 UTC
Learn by doing :P
Jon Lucas
@jonslucas
Feb 25 2015 17:27 UTC
@davisec52 let me with it a minute
Evan Davis
@davisec52
Feb 25 2015 17:27 UTC
@jonslucas Great, thanks.
Jon Lucas
@jonslucas
Feb 25 2015 17:28 UTC
I haven't figured out why it isn't returning, but I haven't used the .filter() method much
@chrisdziewa Learn by breaking, is more like it
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:28 UTC
@jonslucas that. haha
@davisec52 Filter returns an element based on whether it meets a condition
Evan Davis
@davisec52
Feb 25 2015 17:30 UTC
right
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:30 UTC
If you want to change something you may want to use map
Evan Davis
@davisec52
Feb 25 2015 17:30 UTC
I just want it to return the elements that meet the condition of the filter

function fil(arr) {
    arr.filter(function(q) {
        if(q < 7) {
           return q; 
        }
    });
}
fil([1, 2, 7, 9, 12]);
This also does not return.
Any idea what I'm doing in error?
Danny Fritz
@dannyfritz
Feb 25 2015 17:32 UTC
fil isn't returning anything
Evan Davis
@davisec52
Feb 25 2015 17:32 UTC
Yes. I don't understand why.
Danny Fritz
@dannyfritz
Feb 25 2015 17:32 UTC
you need a return statement in fil to return something.
Evan Davis
@davisec52
Feb 25 2015 17:33 UTC
There is a return statement.
please clarify
Danny Fritz
@dannyfritz
Feb 25 2015 17:33 UTC
there is a return inside your filter function.
but not in fil
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:33 UTC
function fil(arr) {
    var result = arr.filter(function(q) {
        if(q < 7) {
           return q; 
        }
    });
    return result;
}
fil([1, 2, 7, 9, 12]);
Evan Davis
@davisec52
Feb 25 2015 17:33 UTC
that also ldoes not work
sorry.
moment
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:35 UTC
@davisec52 Filter doesn't change the current array. It returns a new one containing elements that have met your condition. That is why you must assign it to a variable.
Evan Davis
@davisec52
Feb 25 2015 17:35 UTC
@chrisdziewa I see it now.
Thank you
I knew it was something ridiculously simple
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:36 UTC
No problem. There are so many functions that do similar things. It's hard to keep track of them sometimes ha. I am still trying to wrap my head around call and apply.
You can also shorten your conditional statement like this:
return q < 7;
Your filter function keeps track of the element you are currently on.
Evan Davis
@davisec52
Feb 25 2015 17:40 UTC
I'm sure there is much to learn about filters. I was trying to see if I could apply it to the the where are thou bonfire challenge.
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:40 UTC
ah yeah that one
fun times ha
Evan Davis
@davisec52
Feb 25 2015 17:40 UTC
I'm sure it can be applied; the question is whether I can apply it, ho, ho.
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:41 UTC
haha yup
Danny Fritz
@dannyfritz
Feb 25 2015 17:41 UTC
right, doing a return q will fail on a 0.
Oliver
@Dadsaster
Feb 25 2015 17:41 UTC
Does anyone have a different approach to this one - maybe using match?
// Returns an array of unique values in original order
function unite(arr1, arr2, arr3) {
  // make one big array for sending to the unique function
  var sender = arr1.concat(arr2, arr3);
  var arrFinal = [];
  //does the array "list" contain the string "value"
  function contains(value, list) {
    for(var i = 0; i < list.length; i++) {
      if(list[i] === value) return true;
    }
    return false;
  }
  //If the value is unique - add it to arrFinal
  function unique(bigList) {
    arrFinal.push(bigList[0]); //first value is always unique
    // iterate through the array
    for (var i = 0 ; i < bigList.length ; i++) {
      // if the element from biglist does not exist in the array
      // add it to the final array
      if (!contains(bigList[i], arrFinal)) {
        arrFinal.push(bigList[i]);
      }
    } 
  }
  unique(sender); 
  return arrFinal;
}

unite([1, 3, 2], [1, [5]], [2, [4]]);
Chris Dziewa
@chrisdziewa
Feb 25 2015 17:42 UTC
as that symmetric difference?
Jon Lucas
@jonslucas
Feb 25 2015 17:44 UTC
instead of contains, I used the .indexOf() method to test if an element is in an array. Like this arrFinal.indexOf(bigList[i]) < 0
Danny Fritz
@dannyfritz
Feb 25 2015 17:48 UTC
does this work @Dadsaster?
function unite() {
  return R.reduce(R.compose(R.uniq, R.concat), [], arguments);
}
Oliver
@Dadsaster
Feb 25 2015 17:50 UTC
@dannyfritz - that is over my head - I'll have to do some studying
Jon Lucas
@jonslucas
Feb 25 2015 17:50 UTC
Is that ramda?
Danny Fritz
@dannyfritz
Feb 25 2015 17:50 UTC
yeah, ramda is injected into the bonfires VM's
Jon Lucas
@jonslucas
Feb 25 2015 17:50 UTC
I was aware that it was there, but haven't looked into it
before today
my functional programming know-how is next to nothing
Jon Lucas
@jonslucas
Feb 25 2015 17:52 UTC
nice
Oliver
@Dadsaster
Feb 25 2015 17:52 UTC
I'll stick to pure js for now
Danny Fritz
@dannyfritz
Feb 25 2015 17:53 UTC
basically, take all arguments and then accumulate only unique values.
compose just pipes 2 functions together. in this case i pipe the result of concat into uniq
Nathan
@terakilobyte
Feb 25 2015 19:26 UTC
@chrisdziewa nice to see you solved map the debris! as an added challenge, use map intstead of a for loop ;)
Cristián Berríos
@crisberrios
Feb 25 2015 20:10 UTC
@terakilobyte and @dannyfritz
I have a question for you
Danny Fritz
@dannyfritz
Feb 25 2015 20:11 UTC
sure
Nathan
@terakilobyte
Feb 25 2015 20:11 UTC
what’s up?
Cristián Berríos
@crisberrios
Feb 25 2015 20:11 UTC
I was trying to do the group an array into chunks bonfire
using Ramda
Nathan
@terakilobyte
Feb 25 2015 20:11 UTC
chunky monkey?
Cristián Berríos
@crisberrios
Feb 25 2015 20:11 UTC
but I couldn't figure a way to make it into a one liner
I was guessing that using groupBy would be useful
but since it does not pass the index of the element if it's an array
you can't really group them that way
Jon Lucas
@jonslucas
Feb 25 2015 20:15 UTC
@terakilobyte is Array.prototype.map() preferable to a for loop?
Cristián Berríos
@crisberrios
Feb 25 2015 20:16 UTC
@jonslucas yes it is
Jon Lucas
@jonslucas
Feb 25 2015 20:17 UTC
Is it more efficient? Or why is it more preferable?
Nathan
@terakilobyte
Feb 25 2015 20:20 UTC
map returns you a new array
but the more important part is map is more inline with functional programming
you definitely want to get used to using it
Jon Lucas
@jonslucas
Feb 25 2015 20:22 UTC
yeah, I definitely need to focus on more functional programming. I have the same problem with python.
I guess I was thinking that the creation of a new array would require more up-front memory, as opposed to modifying the already existing array. But, in this, I know very little.
Cristián Berríos
@crisberrios
Feb 25 2015 20:26 UTC
function chunk(arr, size) {
  var answer = [];
  _.forEachIndexed(function (x,index) { 
    var slot = Math.floor(index/size);
    answer[slot] = answer[slot] || [] ; 
    answer[slot].push(x);
  },arr);
  return answer;
}
chunk(['a', 'b', 'c', 'd'], 2);
If there were a groupByIndexed, the function should only return the slot and it would be shorter
I think I will propose it to Ramda :P
Danny Fritz
@dannyfritz
Feb 25 2015 20:27 UTC
reduceIndexed
Cristián Berríos
@crisberrios
Feb 25 2015 20:28 UTC
hmm
yes, let's try again
I don't see making the function shorter
Danny Fritz
@dannyfritz
Feb 25 2015 21:09 UTC
@crisberrios I feel like i'm onto something, but not sure how to get chunker smaller http://jsbin.com/rexumoleso/3/edit?js,console
This message was deleted
Danny Fritz
@dannyfritz
Feb 25 2015 21:15 UTC
edit 3 is fairly functional now http://jsbin.com/rexumoleso/3/edit?js,console
Cristián Berríos
@crisberrios
Feb 25 2015 21:19 UTC
well, certainly it's more functional
but not shorter :P
Danny Fritz
@dannyfritz
Feb 25 2015 21:19 UTC
definitely not more readable
Cristián Berríos
@crisberrios
Feb 25 2015 21:20 UTC
function chunk(arr, size) {
  var slices = Math.floor(arr.length/size);
  var i= 0, answer = [];
  while(i<slices) {
    answer.push(arr.splice(0,size));
    i++;
  }
  if(arr.length > 0) answer = answer.concat([arr]);
  return answer;
}
this would be my default non-functional answer
and I would avoid splice for larger arrays
Danny Fritz
@dannyfritz
Feb 25 2015 21:24 UTC
how does this look?
function chunk(arr, size) {
  var slices = Math.ceil(arr.length/size);
  var answer = [];
  R.times(function (i) {
    answer.push(R.take(size, R.drop(i*size, arr)));
  }, slices);
  return answer;
}
Cristián Berríos
@crisberrios
Feb 25 2015 21:24 UTC
that does make more sense
Danny Fritz
@dannyfritz
Feb 25 2015 21:25 UTC
you had a bug in Math.floor by the way
test with this ['a', 'b', 'c', 'd', 'e']
Cristián Berríos
@crisberrios
Feb 25 2015 21:25 UTC
it works and passes all tests
Danny Fritz
@dannyfritz
Feb 25 2015 21:26 UTC
yeah, i guess because of that last if statement
it catches it
even with the while loop a simpler way:
function chunk(arr, size) {
  var slices = Math.ceil(arr.length/size);
  var i= 0, answer = [];
  while(i<slices) {
    answer.push(arr.splice(0,size));
    i++;
  }
  return answer;
}
omg, i need to stop rewriting it
function chunk(arr, size) {
  return R.reduceIndexed(function (chunks, value, i) {
    chunks.push(R.take(size, R.drop(i*size, arr)));
    return chunks;
  }, [], R.range(0, Math.ceil(arr.length/size)));
}
Cristián Berríos
@crisberrios
Feb 25 2015 21:32 UTC
I thnk I tried the method without concat and it gave an error somewhere
but didn't test it through
I liked this version
function chunk(arr, size) {
  var slices = Math.ceil(arr.length/size);
  var answer = [];
  R.times(function (i) {
    answer.push(R.take(size, R.drop(i*size, arr)));
  }, slices);
  return answer;
}
short and readable
Danny Fritz
@dannyfritz
Feb 25 2015 21:35 UTC
yeah, it is essentially a reduce with a stray var
anytime i see a [] before a loop i know it should be a map or reduce
Nathan
@terakilobyte
Feb 25 2015 21:37 UTC
@dannyfritz you should write us some list manipulation challenges for bonfire ;)
Danny Fritz
@dannyfritz
Feb 25 2015 21:38 UTC
lol
Nathan
@terakilobyte
Feb 25 2015 21:39 UTC
serious :)
I’d like to have about 100 bonfires
list and object manipulation is a big deal
we use it all over the place
Darryl Dixon - Piece Digital
@piecedigital
Feb 25 2015 21:41 UTC
On what part of front end?
Danny Fritz
@dannyfritz
Feb 25 2015 21:41 UTC
he'll be using it a ton once he switches to react
on the front end
Cristián Berríos
@crisberrios
Feb 25 2015 21:41 UTC
well, I'm going to get some nonprofit work done :P nice FP session @dannyfritz
Danny Fritz
@dannyfritz
Feb 25 2015 21:43 UTC
indeed
it makes me pine for haskell
Quincy Larson
@QuincyLarson
Feb 25 2015 21:44 UTC
@piecedigital we’ll have thousands of courseware challenges, many of which will be focused on front end
Darryl Dixon - Piece Digital
@piecedigital
Feb 25 2015 21:44 UTC
What's the emphasis on front end as opposed to back end?
Cristián Berríos
@crisberrios
Feb 25 2015 21:53 UTC
what do you mean @piecedigital?
Nathan
@terakilobyte
Feb 25 2015 22:12 UTC
so the bottom line is we’re switching to an isomorphic framework
the line between front and backend is very much blurred
Darryl Dixon - Piece Digital
@piecedigital
Feb 25 2015 22:13 UTC
ehh
Jonathan
@jonathantimm
Feb 25 2015 22:14 UTC
hey guys could I ask a very simple javascript questio
Nathan
@terakilobyte
Feb 25 2015 22:14 UTC
sure go ahead
Jonathan
@jonathantimm
Feb 25 2015 22:15 UTC
I'm just confused about functions. I get that you have to declare what a function does, but how do you indicate what your input will be called and make sure it knows when you're giving it an input?
Nathan
@terakilobyte
Feb 25 2015 22:16 UTC
well
Jonathan
@jonathantimm
Feb 25 2015 22:16 UTC
Like this is from the lesson, here:
Cristián Berríos
@crisberrios
Feb 25 2015 22:16 UTC
that's a complex question
Nathan
@terakilobyte
Feb 25 2015 22:16 UTC
^
ok, post the code you hav ea question about
Cristián Berríos
@crisberrios
Feb 25 2015 22:16 UTC
because functions in JavaScript don't explicitly care about what parameters you pass to them
Jonathan
@jonathantimm
Feb 25 2015 22:17 UTC
ohh
so for example
Cristián Berríos
@crisberrios
Feb 25 2015 22:17 UTC
function message () {
console.log(arguments[0]);
if(arguments[1] === true) {
return false ;
}
}
Jonathan
@jonathantimm
Feb 25 2015 22:18 UTC
var greeting = function (name) {
    console.log("Great to see you," + " " + name);
};

// On line 11, call the greeting function!
greeting("Jonathan");
I just didn't get how "Jonathan" and "name" were connected in the programming
but what you're saying is that it doesn't need to know why you're calling it a name, or whatever. it just puts in the input
Nathan
@terakilobyte
Feb 25 2015 22:19 UTC
ok
so when you invoked your function, greeting
you implicitly said something like greeting(name = Jonathan)
Jonathan
@jonathantimm
Feb 25 2015 22:20 UTC
ah yeah i see that
Nathan
@terakilobyte
Feb 25 2015 22:20 UTC
since the function declaration takes a paramater called name
greeting(“Jonathan”) tells the function to use Jonathan as the value for name
Cristián Berríos
@crisberrios
Feb 25 2015 22:21 UTC
var greeting = function (name) {
    console.log("Great to see you," + " " + name + arguments[1]);
};

// On line 11, call the greeting function!
greeting("Jonathan","Smith");
but if you pass more parameters they're still there
in the arguments object
just not assigned to a variable
Nathan
@terakilobyte
Feb 25 2015 22:22 UTC
for now if you are just learning about JS I’d recommend not worrying about that though
Cristián Berríos
@crisberrios
Feb 25 2015 22:22 UTC
when building functions just remember to give parameters a logic name
don't use function cat (moon) { return ("Hello" + moon) }
Darryl Dixon - Piece Digital
@piecedigital
Feb 25 2015 22:23 UTC
Ha
Jonathan
@jonathantimm
Feb 25 2015 22:23 UTC
okay, yeah i'm very basic here
Darryl Dixon - Piece Digital
@piecedigital
Feb 25 2015 22:23 UTC
that edit lol
Cristián Berríos
@crisberrios
Feb 25 2015 22:24 UTC
:P
my jshint part of the brain is 1 sec behind
Evan Davis
@davisec52
Feb 25 2015 22:24 UTC
Quck question -- I'd appreciate help understanding why the function below does
not work. The result should have the values 2, 3 filtered from
the resulting array. Instead, the original array (first argument)
is returned.

function destroyer(arr) {
    var arg = [];
    var result = [];
    var i;
    var j;
    var k;
    for(i = 1; i < arguments.length; i++) {
        arg.push(arguments[i]);
    }
    for(j = 0; j < arr.length; j++) {
        for(k = 0; k < arg.length; k++) {
            if(arr[j] !== arg[k]) {
                //result[j] = arr[j];
                result.push(arr[j]);
            }
        }
    }
    return result;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Cristián Berríos
@crisberrios
Feb 25 2015 22:27 UTC
well
I'd advice about too many nested loops
if(arr[j] !== arg[k]) {
                //result[j] = arr[j];
                result.push(arr[j]);
            }
I think the problem might be here
Evan Davis
@davisec52
Feb 25 2015 22:27 UTC
@crisberrios how so?
Cristián Berríos
@crisberrios
Feb 25 2015 22:27 UTC
you are comparing the 1st element of the array
let's say arr[j] = 1
Evan Davis
@davisec52
Feb 25 2015 22:28 UTC
continue
Cristián Berríos
@crisberrios
Feb 25 2015 22:28 UTC
and then you want to compare them with all the values in arg
and they are 2,1,3
at the 1st iteration, you decide that they are different
Evan Davis
@davisec52
Feb 25 2015 22:29 UTC
no, values in arg are 2, 3
Cristián Berríos
@crisberrios
Feb 25 2015 22:29 UTC
but it shouldn't
so you push 1 into the answer
(just an example)
same for your example
if comparing 2 against 2,3
it won't add it at the 1st iteration
but it will at the 2nd
you should only decide after comparing all the items
or stop the test after the 1st failed case
Evan Davis
@davisec52
Feb 25 2015 22:30 UTC
I thought !== would apply to all iterations.
Cristián Berríos
@crisberrios
Feb 25 2015 22:31 UTC
nope, that's why it's an iteration
1 step at a time only
Evan Davis
@davisec52
Feb 25 2015 22:31 UTC
I tried to do this using filter and forEach with similar results
Cristián Berríos
@crisberrios
Feb 25 2015 22:31 UTC
filter is good for this exercise
and also look into indexOf
Evan Davis
@davisec52
Feb 25 2015 22:31 UTC
(By the way, I sorted out--no pun intended--the where art though challenge).
I was thinking that indexOf might make the answer too complex. This ought to be really simple
Just comparing values in one array to those in a second array and pushing the correct values.
Szajbob
@Szajbob
Feb 25 2015 22:33 UTC
Hi guys!
@crisberrios do you have a minute? :smile:
or maybe you @davisec52 ?
I'm stuck on a bonfire 'where art thou'
Cristián Berríos
@crisberrios
Feb 25 2015 22:36 UTC
sure @Szajbob
Szajbob
@Szajbob
Feb 25 2015 22:36 UTC
if you could just give me a clue which method I should use for this one I think I can handle the rest
I have a problem converting objects from array in to array
Cristián Berríos
@crisberrios
Feb 25 2015 22:37 UTC
@davisec52 filter.... if array item .indexOf (arg) < 0 then push to answer
can't get simpler than that
Evan Davis
@davisec52
Feb 25 2015 22:37 UTC
@crisberrios ok, then.
Cristián Berríos
@crisberrios
Feb 25 2015 22:38 UTC
@Szajbob you shouldn't be converting collection objects into an array
for that exercise
Evan Davis
@davisec52
Feb 25 2015 22:38 UTC
@Szajbob In the end, I came up with a solution using filter.
Szajbob
@Szajbob
Feb 25 2015 22:39 UTC
so filter method?
Evan Davis
@davisec52
Feb 25 2015 22:39 UTC
The big problem for me was figuring out how to iterate properly over the object properties and values.
Szajbob
@Szajbob
Feb 25 2015 22:39 UTC
exactly! same here
so the filter method is the answer for this?
Evan Davis
@davisec52
Feb 25 2015 22:40 UTC
@Szajbob The filter method gave me a fairly simple solution.
Szajbob
@Szajbob
Feb 25 2015 22:40 UTC
ok, got it, thank you and back to work :smile:
Cristián Berríos
@crisberrios
Feb 25 2015 22:41 UTC
@Szajbob more than filter, the key is knowing how to compare properties between objects
Evan Davis
@davisec52
Feb 25 2015 22:41 UTC
@Szajbob Good hunting!
Nathan
@terakilobyte
Feb 25 2015 22:41 UTC
when using lists, you should always, always always immediately think of map, filter, and reduce
Cristián Berríos
@crisberrios
Feb 25 2015 22:41 UTC
and Object.keys
Nathan
@terakilobyte
Feb 25 2015 22:41 UTC
I can’t stress enough how important those methods and the ideas behind their usage are
Szajbob
@Szajbob
Feb 25 2015 22:42 UTC
I searched around for it - comparing properties between objects, and couldn't find anything specific
ok, so to sum it up I should learn everything about filter, map, reduce and keys method?
Cristián Berríos
@crisberrios
Feb 25 2015 22:43 UTC
:thumbsup:
Germaine Pannell
@germainep
Feb 25 2015 22:43 UTC
hey guys when working on bonfires is changing the arguments acceptable
for example
Evan Davis
@davisec52
Feb 25 2015 22:43 UTC
@Szajbob I found JS Succinctly to be of help, too. Recommendation from @crisberios.
Very readable book.
Free, too.
Germaine Pannell
@germainep
Feb 25 2015 22:44 UTC
function sym(arr) {
  return arr;
}

sym([1, 2, 3],[5, 2, 1, 4]);
instead of this can i do
function sym(arr, arr2) {
  return arr;
}

sym([1, 2, 3],[5, 2, 1, 4]);
Szajbob
@Szajbob
Feb 25 2015 22:44 UTC
@davisec52 great! downloading it now :smile:
Nathan
@terakilobyte
Feb 25 2015 22:45 UTC
doubtful it will pass the tests @germainep
Cristián Berríos
@crisberrios
Feb 25 2015 22:45 UTC
@germainep it you are 100% sure there will only be 2 arguments I don't see why not
since the tests will only call the function and pass arguments
Nathan
@terakilobyte
Feb 25 2015 22:46 UTC
and if it did, changing the arguments is still not actually solving the challenge as intended
Cristián Berríos
@crisberrios
Feb 25 2015 22:46 UTC
^
Nathan
@terakilobyte
Feb 25 2015 22:47 UTC
idea for more bonfires
Germaine Pannell
@germainep
Feb 25 2015 22:47 UTC
@crisberrios as soon as you said that i realize there will be more than two @terakilobyte i understand I know what I need to do now thanks guys
Nathan
@terakilobyte
Feb 25 2015 22:47 UTC
variable length function calls
ooh, can use that to reinforce currying
thanks @germainep !
Matthew Harames
@Harames
Feb 25 2015 23:42 UTC
@AmmarAliShah Changed his picture