These are chat archives for FreeCodeCamp/Help

2nd
Feb 2015
Evan Davis
@davisec52
Feb 02 2015 00:18

arr.forEach(function(a){ 
    if (nums.indexOf(a) === -1) {
      nums.push(a);
      counts.push(1);
    } else {
      counts[nums.indexOf(a)]++;
    }
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:19
Array.prototype.indexOf returns -1 when the item you pass in isn't found in the array, if that's what you're confused about
Evan Davis
@davisec52
Feb 02 2015 00:19
I understand that counts[nums.indexOf(a)]++ is counting the number of occurences of an array element.
@wdgreg Right. I stared at that a long time before it hit me that that must be what it means.
Wasn't sure.
Really nice statement.
@wdgreg So, counts.push(1) adds 1 to counts for every a that is added to nums?
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:21
No, not quite, let me run through it line by one, it'll help you understand
Evan Davis
@davisec52
Feb 02 2015 00:21
@wdgreg Thank you
Fire away
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:21
So what it does is the forEach goes through arr one by one, and the element it's currently expecting is called a
Evan Davis
@davisec52
Feb 02 2015 00:22
that is clear
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:22
then it checks if 'a' - again, this is the element in the array in question, in a normal for-loop, this would be arr[i] - is in nums or not
Evan Davis
@davisec52
Feb 02 2015 00:22
so far so good
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:22
if it is not, it pushes a onto the 'num's array, which is simply an array to contain all unique elements of arr
at the same time it pushes '1' to the counts array
what this means is that there are now two arrays
one to hold the unique elements, and one to hold their frequencies
and the index of both is always the same
and with the else statement, 1 is added to the counts array of the correct element if it is found in arr (so if it's a recurring element)
this way, in the end there are two arrays, nums holds the unique elements, and counts holds their frequencies
in the next line of code, 'highest' then checks the highest number in the 'counts' array, and because the indexes are the same, it can be used in the final return statement
as an example, if you pass in [1,1,2,3], the result of that snippet will be two arrays: [1,2,3] and [2,1,1]
Evan Davis
@davisec52
Feb 02 2015 00:27
That is pretty clear. What is not so apparent to me is the relationship between counts.push(1) and nums.push(a).
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:28
right. the relationship is basically that if a new element is found, I add the new element to nums, and [1] to counts
because it is an until then unique element (push a to nums), which means that its frequency is 1 (push '1' to counts)
when it is encountered again, counts[wherever 'a' is] gets +1'd
(that last sentence is in the else statement, to be clear)
i remember we talked last time about using an object (as in { 'a' : freq } or an array of arrays (as in [ [ a, freq] ] ), so it turns out in this case I used a third alternative: two arrays
Evan Davis
@davisec52
Feb 02 2015 00:31
I will have to play with that. It would not have occured to me that that +1s would count occurences of unique elements.
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:32
Yes, I realize that "counts.push(1)" might sound different from what it actually is :)
Evan Davis
@davisec52
Feb 02 2015 00:32
Now that I see the code, I understand what you were getting at.
very cool.
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:32
but if arr = [], arr.push(1) will just make arr = [1]
Evan Davis
@davisec52
Feb 02 2015 00:33
yes
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:33
also, something you may want to investigate is the Math.max.apply on line 21
I'm not sure how far you are in your JS learning, but apply is incredibly useful
because it allows you to pass in the elements of an array as arguments of a function
Evan Davis
@davisec52
Feb 02 2015 00:35
I looked that up. It was something new.
Also checked out eval(), which was something used in another solution.
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:35
And in case it's not clear, the null is what this is then bound too
Yes, eval is powerful, but it's generally very frowned upon to use in regular code
Evan Davis
@davisec52
Feb 02 2015 00:39
I think I will try to construct some simple statements using code similar to your construction to get the hang of it.
This is much deeper than my current beginner's level.
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:40
Are you on codewars? codewars will bring you up to speed on this kind of stuff
Evan Davis
@davisec52
Feb 02 2015 00:41
@wdgreg Thank you very much for your explanation. Ive made notes. No, not on codewars right now.
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:41
I highly recommend signing up to codewars and doing level 8 and level 7 katas in the 'Fundamentals' category
Evan Davis
@davisec52
Feb 02 2015 00:41
I've got to step away from the computer for a bit. Thank you again!
Gregory Scheerlinck
@greg-js
Feb 02 2015 00:41
No problem, good luck!
Evan Davis
@davisec52
Feb 02 2015 00:42
@wdgreg Ok. I'll take your advice and check it out!
Ashley Drake
@aldraco
Feb 02 2015 01:44
hello help channel. hope everyone is enjoying the superbowl (food)
i have a question on the regex challenge.
in lesson 12, the task is to select the date, then repeat the date, like this:
capture text May 1969 result: May 1969, 1969
why does the ^ $ not work here?
thanks.
Nathan
@terakilobyte
Feb 02 2015 01:46
what have you tried?
also, bookmark regex101.com
it will help you see what the regex is doing
Ashley Drake
@aldraco
Feb 02 2015 01:47
ugh I had them in the wrong order.
^(\w+\s(\d+))$
the 101 site is helpful, thanks
Nathan
@terakilobyte
Feb 02 2015 01:48
happy coding!
Ashley Drake
@aldraco
Feb 02 2015 01:48
don't you hate when it's typing mistakes?? sorry to bother you guys
Dominic Jones
@towwiow
Feb 02 2015 03:59
Anybody around whose finished task 16 around? I need some help figuring this out
Matthew Harames
@Harames
Feb 02 2015 04:01
@towwiow what
Dominic Jones
@towwiow
Feb 02 2015 04:03
Nathan told me what I should be looking in the css - bootstrap - grid system to find out the option I need to change to get it all to the one column and that it's one thing will fix it but I'm not finding what it is.
you have any more tips for me to look?
Nathan
@terakilobyte
Feb 02 2015 04:03
link your pen @towwiow ?
Patrick Ly
@patrickly
Feb 02 2015 04:03
@towwiow try looking for media.
Matthew Harames
@Harames
Feb 02 2015 04:04
@towwiow I made it on column by moving the div around column one around the whole page. Yes it is cheating, but it worked.
Dominic Jones
@towwiow
Feb 02 2015 04:05
lol @PKMNinja
@terakilobyte - i just logged in and it's hitting me with this sign-up page. You gotta go pro? I thought it was free?
hold on.
Nathan
@terakilobyte
Feb 02 2015 04:08
umm
shouldn't need to go pro
Dominic Jones
@towwiow
Feb 02 2015 04:10
yeah, i didn't think so. and i'm pretty sure I logged in with github. but it's not showing me as logged in, logged in with username and pword and it's still not showing me as logged in. tried to make an account, it's recognizing my account lol.
It was Opera, codepen must not like that browser..
Nathan
@terakilobyte
Feb 02 2015 04:16
ah
good to know ;)
so you are like the one person who uses Opera
Dominic Jones
@towwiow
Feb 02 2015 04:23
haha.
Patrick Ly
@patrickly
Feb 02 2015 04:34
@towwiow css, line 1913
col-md-1 to 12 @towwiow
Dominic Jones
@towwiow
Feb 02 2015 04:36
That sure did make it all one.. can you explain it to me ? taking it out makes it all one layout
Ben Clist
@BenClist
Feb 02 2015 04:36
pretty sure you should be changing the HTML in that challenge, not messing with Bootstrap's CSS
Dominic Jones
@towwiow
Feb 02 2015 04:37
but is there an adjustment you can make to that css other than just taking it out
Patrick Ly
@patrickly
Feb 02 2015 04:37
@towwiow I just put /* in front of @media on line 1913.
Dominic Jones
@towwiow
Feb 02 2015 04:37
This page is currently using a two-column layout, with the main content on the left and additional navigation on the right. See if you can make it a one-column layout.
Ben Clist
@BenClist
Feb 02 2015 04:37
removing a media query definitely isn't the way to solve that challenge, you're just defeating the purpose of using Bootstrap in the first place
Dominic Jones
@towwiow
Feb 02 2015 04:38
@BenClist - it doesn't say focus to edit the css or the html specifically
Patrick Ly
@patrickly
Feb 02 2015 04:38
@towwiow unfortunately, I don't really understand it. I had to search the archive on freecodecamp chat. lol
Dominic Jones
@towwiow
Feb 02 2015 04:39
lol, i got ya.
@BenClist any insights?
Ben Clist
@BenClist
Feb 02 2015 04:40
There's a change you can make in the HTML, sorry I'm at work so can't respond straight away
Dominic Jones
@towwiow
Feb 02 2015 04:40
No, it's cool.
I'm searching the html now.
Ben Clist
@BenClist
Feb 02 2015 04:41
Basically bootstrap works by giving a set of pre-defined CSS classes
It works on a grid of 12 columns, so a particular class will tell a div how many columns it can occupy
Dominic Jones
@towwiow
Feb 02 2015 04:42
all the columns in the css are pre-defined as the .col-md-x right ? x being 1 - 12
Ben Clist
@BenClist
Feb 02 2015 04:43
yeah exactly
so a div with a class of col-md-9 is going to occupy 75% of the width of the page (9/12)
Nathan
@terakilobyte
Feb 02 2015 04:44
^
my cryptic hint about looking at the grid system
Dominic Jones
@towwiow
Feb 02 2015 04:45
lol, yeah. I feel like i'm a drunk farmer looking for a needle in a haystack hahaha
Ben Clist
@BenClist
Feb 02 2015 04:47
You only need to change one thing in the HTML ;)
Dominic Jones
@towwiow
Feb 02 2015 04:48
yeah, that's what Nathan told me.
towwiow @towwiow puts the html in brackets so he doesn't have to search through this super small window.
Dominic Jones
@towwiow
Feb 02 2015 04:52
and it's going to be in a div ? @terakilobyte @BenClist
delete this on line 112??? <div class="col-md-9" role="main">
Ben Clist
@BenClist
Feb 02 2015 04:59
You don't want to delete anything
@towwiow If you think about it, if we're saying a Div can occupy 9 of 12 columns then it's going to leave room for another div to occupy 3, however if we tell it to occupy 12 then it's going to push a div that would otherwise sit next to it to underneath
so instead of having a 9/12 column and a 3/12 column sat next to each other you'd have a 12/12 column with a 3/12 column directly underneath. So instead of having 2 columns you've effectively only got 1
in terms of how they look on the page
Patrick Ly
@patrickly
Feb 02 2015 05:02
<div class="col-md-9" role="main"> change to <div class="col-md-12" role="main">???
Nathan
@terakilobyte
Feb 02 2015 05:02
give it a try
Dominic Jones
@towwiow
Feb 02 2015 05:03
@BenClist thanks for the breakdown - makes much more sense.
Nathan
@terakilobyte
Feb 02 2015 05:04
I think my next front end geekout is going to be google material design
it looks pretty good
Dominic Jones
@towwiow
Feb 02 2015 05:05
and.. just for good measure it's not supposed to look pretty, it's just going to push it down to the bottom.
Ben Clist
@BenClist
Feb 02 2015 05:05
That's as far as I went with it, guess you could spend time making it look pretty if you wanted to but the best way to do that is probably to make it 2 column again :)
Dominic Jones
@towwiow
Feb 02 2015 05:06
lol, nah I'll pass.
wking2014
@wking2014
Feb 02 2015 05:06
Add a CSS declaration of "text-decoration: underline" for the ":hover" state of all events, then force the hover state on our "Run 5K" event to see the new CSS declaration take effect.
You maked it now?
Dominic Jones
@towwiow
Feb 02 2015 05:07
hmm?
wking2014
@wking2014
Feb 02 2015 05:08
@towwiow I can't do it,too
my english is poor,can you understand me?
This challegne in the codeschool.
nobody here?
Nathan
@terakilobyte
Feb 02 2015 05:10
@wking2014 those are kind of buggy
wking2014
@wking2014
Feb 02 2015 05:10
bug?
Nathan
@terakilobyte
Feb 02 2015 05:11
hit and miss if they will work or not
yes, they don't work all the time
wking2014
@wking2014
Feb 02 2015 05:11
skip it now?
Nathan
@terakilobyte
Feb 02 2015 05:11
what language do you speak?
yeah, skip it
Ben Clist
@BenClist
Feb 02 2015 05:11
That particular one I had to skip @wking2014 it just didn't recognise I'd done it
wking2014
@wking2014
Feb 02 2015 05:11
Chinese
Nathan
@terakilobyte
Feb 02 2015 05:12
ah, don't know if we have anyone that speaks chinese that could help you, sorry
wking2014
@wking2014
Feb 02 2015 05:12
here can't use picture?
Dominic Jones
@towwiow
Feb 02 2015 05:12
Quincy could lol
Nathan
@terakilobyte
Feb 02 2015 05:12
well I think quincy's wife could
wking2014
@wking2014
Feb 02 2015 05:13
LOL?
Dominic Jones
@towwiow
Feb 02 2015 05:13
@wking2014 if you've changed it but it didn't respond and recognize the change, go to the next challenge
Nathan
@terakilobyte
Feb 02 2015 05:13
LOL means he's chuckling
Dominic Jones
@towwiow
Feb 02 2015 05:13
:)
wking2014
@wking2014
Feb 02 2015 05:15
oh,i think it's a popular game in China
OK,thank you!
Dominic Jones
@towwiow
Feb 02 2015 05:16
That's league of legends, not laughing out loud
X-P
wking2014
@wking2014
Feb 02 2015 05:17
what means x-p?
You play it,too?
Dominic Jones
@towwiow
Feb 02 2015 05:25
No I don't play it. It's supposed to be an emoticon like :-) // :-( // X-P
wking2014
@wking2014
Feb 02 2015 05:27
ok
it's so bad that i can't watch the video
Evan Davis
@davisec52
Feb 02 2015 16:02

In an attempt to better understand for-loops and forEach construction, in the sample below I used two for-loops to find matched pairs of numbers and also count the number of matched pairs.

I've tried to convert this to a construction using forEach, but haven't been able to get the same result. I feel like I'm missing something really simple and would appreciate a push in the right direction.


function list(arr) {
    var counter = [];
    var indicator = 0;
    for(var i = 0; i < arr.length; i++) {
        for(var j = i+1; j < arr.length; j++) {
            if(arr[i] === arr[j]) {
                counter.push(arr[j]);
                indicator++;
            }
        }
    }
    return indicator;
}
list([2, 2, 3, 3, 4, 5, 7, 7]);
or return counter
Gregory Scheerlinck
@greg-js
Feb 02 2015 16:08
you're using indicator to count the amount of matched pairs?
Evan Davis
@davisec52
Feb 02 2015 16:09
@wdgreg well, I'm just trying to get a better grasp of what the for-loop is doing.
in this case, the indicator is counting matched pairs. In the progression of things, I'll get up to counting the number of instances of each element.
My first task was just to convert this to a forEach construction. My attempts didn't go anywhere.
Gregory Scheerlinck
@greg-js
Feb 02 2015 16:10
But the code seems to work fine, no?
Evan Davis
@davisec52
Feb 02 2015 16:10
Yes, this sample works fine.
Is it possible to rewrite this as forEach?
Gregory Scheerlinck
@greg-js
Feb 02 2015 16:11
counter.push(arr[j]); is unnecessary here, but I see nothing wrong with how you're counting the amount of matched pairs
Evan Davis
@davisec52
Feb 02 2015 16:12
It works fine for counting matched pairs. I wanted to rewrite it as a forEach statement just to learn more about how the statements work.
Gregory Scheerlinck
@greg-js
Feb 02 2015 16:13
Ohh I see, sorry i misread your question
Evan Davis
@davisec52
Feb 02 2015 16:13
I think I tried to say too much in too few words.
Gregory Scheerlinck
@greg-js
Feb 02 2015 16:14
Right, well, if you want to rewrite both for loops as forEach methods, the outer loop is easy: it's arr.forEach(function(a){ //...}));
for the inner one, you have to do the same thing you're doing in your current code: run the loop on the array but start from the next element
to do that, you'll need arr.slice()
as a hint, take a look at what [1,2,3,4,5].slice(2) gives you
wait, that might be a confusing hint. rather check out ['a', 'b', 'c', 'd'].slice(2) :)
Evan Davis
@davisec52
Feb 02 2015 16:18
Thank you. I'll try that out.
Gregory Scheerlinck
@greg-js
Feb 02 2015 16:19
and generally, I find that if you're doing loops inside loops, the forEach method is more confusing than the regular loops. forEach also does not allow you to exit the loop prematurely, you should be aware of that
(with a for-loop, you can use break; or continue;)
Evan Davis
@davisec52
Feb 02 2015 16:20
Good point. Did not realize that break would not work for forEach.
Suzanne Atkinson
@AdventureBear
Feb 02 2015 20:53
Can anyone explain mixins to me with CSS? is it just a way to encapsulate CSS code? like creating a CSS variable? I've scanned this but not sure I get it: http://oocss.org/spec/css-mixins.html
and looking to understand this great piece of art
and good afternoon!
Ben Clist
@BenClist
Feb 02 2015 21:05
Mixins are more like functions in CSS rather than variables
Suzanne Atkinson
@AdventureBear
Feb 02 2015 21:06
so they are dynamic?
like a fade instruction?
Ben Clist
@BenClist
Feb 02 2015 21:06
sort of, so in that example you posted look at the .inner-shadow uner the LESS tab
Suzanne Atkinson
@AdventureBear
Feb 02 2015 21:07
/* Mixins */
.inner-shadow (@x: 0, @y: 0px, @blur: 0px, @spread: 0, @color: transparent) {
    -webkit-box-shadow: inset @x @y @blur @spread @color;
    -moz-box-shadow:    inset @x @y @blur @spread @color;
    box-shadow:         inset @x @y @blur @spread @color;
}
Ben Clist
@BenClist
Feb 02 2015 21:07
it's essentially creating a function that takes the parameters x, y blur, spread, color
Suzanne Atkinson
@AdventureBear
Feb 02 2015 21:07
so others can follow too...
Oh, I see...so it's a function that takes those parameters and does the "stuff".
and for differrnt things you just plug in different parameters
Ben Clist
@BenClist
Feb 02 2015 21:07
so later in the css you can call inner-shadow with those parameters and it will automatically spit out the correct lines for all the vendor prefies
so you don't have to write a line for each vendor prefix, you only have to write it once
Suzanne Atkinson
@AdventureBear
Feb 02 2015 21:08
that's cool. I probabaly need an intermediate project betweeen dash's dancing robot and this thing to practice!
Suzanne Atkinson
@AdventureBear
Feb 02 2015 21:10
where can I find a list of when vendor prefixes are required? I'm still getting my mind wrapped around the CSS3 updates vs CSS1! (I actually read the entire 1.0 spec while recovering from back surgery 10 years ago...and was pretty handy then).
Ben Clist
@BenClist
Feb 02 2015 21:10
looks quite good for learning SASS
Suzanne Atkinson
@AdventureBear
Feb 02 2015 21:10
are mixins a pre-processor thing then?
Ben Clist
@BenClist
Feb 02 2015 21:10
yeah they are
Ryan Malm
@Rybar
Feb 02 2015 21:10
yup. LESS/SASS
Suzanne Atkinson
@AdventureBear
Feb 02 2015 21:10
awesome. Thank you !
Ben Clist
@BenClist
Feb 02 2015 21:11
Greatest website for css/html compatibility, even has data on browser usage by country so you can decide which version you want to support
Suzanne Atkinson
@AdventureBear
Feb 02 2015 21:12
so many cool things to learn! @QuincyLarson I suggested to @terakilobyte the idea of "graduate level" or "elective" pathways in FCC. One of the great things about FCC is keeping track of what I've done and where to go. If I could add some modules like LESS/SASS, MongoDB and the steps for those I could stay on track and still further my learning. I'm not sure I'm up to helping with that in the open source side yet.
Banun Idris
@mininsomniac
Feb 02 2015 21:37
function ArrayAdditionI(arr) { 
  arr.sort(function(a, b){return a - b;}); //sort array in ascending order

  var largest = arr.pop(); //store the largest number to compare

  function subsetsum(target, array) { //recursive function to test combinations
    if (array.length == 0) { //base case
    }
    var n = array[0]; //storing number at first index
    array = array.slice(1); //reducing array length
    return subsetsum(target, array) || subsetsum(target - n, array); //smaller input for recursion
}

  return subsetsum(largest, arr); //first call

}
Could someone help me visualize what happens when a recursive function returns an expression with || please? Does it basically try out every single possible combination? What does the call stack look like (I think this is what is confusing me)? And lastly, would it be possible to rewrite the subsetsum() function using array.reduce()?
am practicing writing recursive functions/finding recursive algorithm solutions to avoid for-loop headaches
Ryan Malm
@Rybar
Feb 02 2015 21:44
Check this out and play, It's proved helpful for me: http://visualgo.net/
Banun Idris
@mininsomniac
Feb 02 2015 21:50
:flushed:
that's exactly what I need!! Thank you thank you @Rybar
Jason Rueckert
@jsonify
Feb 02 2015 22:28
@Rybar I have no idea what's going on at that site. I'm so lost.