These are chat archives for FreeCodeCamp/Help

24th
Jan 2015
Christopher Hutchinson
@cshutchinson
Jan 24 2015 00:40 UTC
coderbytes get the best of me sometimes; time to take a break I guess
Nathan
@terakilobyte
Jan 24 2015 00:49 UTC
@cshutchinson try out codewars too
you'll learn a lot more
Christopher Hutchinson
@cshutchinson
Jan 24 2015 00:49 UTC
ok, I will ty; the higher the kata # the easier right?
or perhaps its the opposite I can’t remember
I’ll look
Nathan
@terakilobyte
Jan 24 2015 01:03 UTC
yes
8 kyu is easiest
the lower the harder
Evan Davis
@davisec52
Jan 24 2015 01:42 UTC
I've been sweating through recursion and found a very helpful video that illustrates what happens when the program is running through a fibonacci sequence. It really clarifies the beanstalk problem. Maybe now I can make sense out of the coderbyte head banger, ArrayAddition. Video at https://www.youtube.com/watch?v=zg-ddPbzcKM&feature=youtu.be.
Ryan Malm
@Rybar
Jan 24 2015 02:34 UTC
Still looking for some css animation help with this one. The desired behavior is that the whole thing spins in place around the white dot when clicked, and transforms. Currently it swings a 90 degree arc around some arbitrary point, I've tried setting the transform origin on various divs, to no avail. This won't do anything here, need to open it in a new window/tab. http://codepen.io/Rybar/pen/xbdNwj
Christopher Hutchinson
@cshutchinson
Jan 24 2015 04:21 UTC
var sum=0;
    var counts = {};
    arr.forEach(function(x) { counts[x] = (counts[x] || 0)+1; });
    arr.forEach(function(x) { sum +=x;});
    return (counts);
returns: { '1': 1, '3': 3, '5': 1 }
how do I access the items in the literal object counts?
ty in advance if anyone knows. I have to hit the bed…been coding too long today
david
@dalvarado
Jan 24 2015 06:42 UTC
all keys are in single quotes, so you would access the values like this:
// this will return 1
return count['5'];
surikmeetr
@surikmeetr
Jan 24 2015 09:16 UTC
I was tackling the ArrayAddition challenge on Coderbyte, but there's something I don't understand. The recursive function would be like this:

code function recursive (l, seq){
if(seq.length === 0){
return (l === 0);
}

var small = seq.shift();
//var small = seq[0];
//seq = seq.slice(1);
return recursive(l, seq) || recursive(l-small, seq);

}

what a mess, sorry. The point I don't understand is why the line small = seq.shift() makes the program fail but the two following lines (commented) work.
Christopher Hutchinson
@cshutchinson
Jan 24 2015 13:00 UTC
@dalvarado thank you so much; it seems I tried everything but that :)
Evan Davis
@davisec52
Jan 24 2015 20:49 UTC

I have also been trying to take on the coderbyte Array addition problem that may be similar to the problem @surikmeetr asked.

I found the code sample below, which indicates true if the sum of any of the elements in an array equal a target number. I think I understand the recursion, but I don't understand how the code arrives at a true/false determination.

The return statement looks like this:


return subsetsum(target, array) || subsetsum(target - n, array);

And here is the complete code sequence:


function subsetsum(target, array) {
    if (array.length == 0) {
        return target == 0;
    }
    var n = array[0];
    array = array.slice(1);
    return subsetsum(target, array) || subsetsum(target - n, array);
}
Ben Clist
@BenClist
Jan 24 2015 21:03 UTC
It's working it out by subtracting from the total rather than adding from 0. If it reaches a round 0 it knows the number could add from 0 to reach the target
step it through in Dev Tools debugger and watch the values of the array and target, should give you some insight
Evan Davis
@davisec52
Jan 24 2015 21:09 UTC
@BenClist Hi. That helps. I figured it was subtracting from the top, but what I'm not getting is how the truthyess is determined.
The if statement says if(array.length == 0) (return target === 0:}. I changed == 0 to === 0. I'm assuming that determines the boolean outcome, but I don't really get how it works.
surikmeetr
@surikmeetr
Jan 24 2015 21:23 UTC
that return statement evaluates target===0. If target is equal to zero, it will thus return true, but if target is not zero it will return false. Hope that helps.
I was actually asking something else about the snippet I posted earlier that has little to do with the algorithm and more with the implementation.
Bin Ury
@teddy-error
Jan 24 2015 21:29 UTC
I neeeeeed some help with Ruby and Rspec
Evan Davis
@davisec52
Jan 24 2015 21:30 UTC
@surikmeetr Thank you. That does help a bit.
Bin Ury
@teddy-error
Jan 24 2015 21:30 UTC
class Dictionary
  attr_reader :entries

  def initialize
    @entries = {}
  end

  def add(entry, val = nil)
    entries[entry] = val
  end
end
does not pass this spec
  it 'can add whole entries with keyword and definition' do
    @d.add('fish' => 'aquatic animal')
    @d.entries.should == {"fish" =>"aquatic animal"}
    @d.keywords.should == ['fish']
  end
Failure/Error: @d.entries.should == {"fish" =>"aquatic animal"}
       expected: {"fish"=>"aquatic animal"}
            got: {{"fish"=>"aquatic animal"}=>nil} (using ==)
why is my hash being returned as a keyword of another hash? I can't even replicate this outside of the rspec test
Jason Rueckert
@jsonify
Jan 24 2015 21:55 UTC
@teddy-error sorry, mate. Since our curriculum revolves around Javascript/Node, not sure who will be able to help you with your Rails issue