These are chat archives for FreeCodeCamp/Help

23rd
Feb 2015
Eduardo Elias
@camponez
Feb 23 2015 00:04
I have finish All my challanges, what should be my next step now?
Cristián Berríos
@crisberrios
Feb 23 2015 00:11
you have to complete the bonfires
then, after you've completed them, you have to complete the form and you'll receive more instructions
You'll be invited to the nonprofits trello board and from there you can add yourself to the projects that interest you. And after that, you will be assigned a project and a pair
Eduardo Elias
@camponez
Feb 23 2015 00:14
oh.. I get.. looks like a miss the bonfires :)
thanks @crisberrios
Jon Lucas
@jonslucas
Feb 23 2015 02:15
Anyone want to help with map the debris? I can't seem to get my numbers to be the exact values being tested for. I can get close, but not right on the value.
Danny Fritz
@dannyfritz
Feb 23 2015 02:41
what equation are you using @jonslucas
Jon Lucas
@jonslucas
Feb 23 2015 02:44
var a = Math.floor(sat.avgAlt)+6380;//alt+earthRadius
var t = (2*Math.PI)*Math.floor(Math.sqrt((a*a*a)/sg));
Danny Fritz
@dannyfritz
Feb 23 2015 02:47
heh yeah, my calculations are very close too
Jon Lucas
@jonslucas
Feb 23 2015 02:48
Yeah, I get within 8 for one of the test cases, but that's as close as I've gotten so far
Danny Fritz
@dannyfritz
Feb 23 2015 02:50
lol, changed my radius to 6367.5 and it passes
Jon Lucas
@jonslucas
Feb 23 2015 02:52
I'll take it
Jon Lucas
@jonslucas
Feb 23 2015 02:54
Yeah, although I had to take some time away from it to figure it out
Darryl Dixon - Piece Digital
@piecedigital
Feb 23 2015 03:01
need help with smallest common multiple http://www.freecodecamp.com/bonfires/smallest-common-multiple
I'm not sure how to approach this but I think recursion can do it
function smallestCommons(arr) {
  arr.sort(function(a,b){
    return a > b;
  } );
  var arr2 = [];
  for(i = arr[0]; i <= arr[1]; i++){
    arr2.push(i);
  }
  //
  var count = 2;
  function countUp(n){
    return divisionTest(n);
  }
  function divisionTest(n){
    if(count < 1000){
      arr2.map(function(a,b){
        if(n % b !== 0){
          count++;
          countUp(count);
        }
        else{
          return count;
        }
      });
    }
  }
  countUp(count);
  return count;
}
smallestCommons([1,5]);
I'm not sure how to detect for the number that's divisible by all.
Jon Lucas
@jonslucas
Feb 23 2015 03:05
What do you mean by 'how to detect for' exactly? Like the test for if it is divisible by all?
FWIW, I didn't use recursion to solve this one
Darryl Dixon - Piece Digital
@piecedigital
Feb 23 2015 03:13
apparently im not checking if a number is divisible by all of the numbers in the array correctly
Jon Lucas
@jonslucas
Feb 23 2015 03:14
I would recommend writing a helper function that does only that. Then placing a call to that function in your smallestCommens() func.
That tends to help me see the flow better.
Or you could through a console.log(n, b); in front of your if(n%... statement?
also, what is the a doing in function(a,b)? I don't see a used outside of the rangeCreation section at the top.
Darryl Dixon - Piece Digital
@piecedigital
Feb 23 2015 03:19
a would just be null
Cristián Berríos
@crisberrios
Feb 23 2015 03:42
@piecedigital we were reviewing that bonfire the other day
smallest common between 3 numbers is smallest(a,smallest(b,c));
so it can be done recursively
Darryl Dixon - Piece Digital
@piecedigital
Feb 23 2015 03:45
It's supposed to be the LCM between all of the number including and between the ones in a given array.
Cristián Berríos
@crisberrios
Feb 23 2015 03:45
yep
Darryl Dixon - Piece Digital
@piecedigital
Feb 23 2015 03:46
So I need to figure that out.
Cristián Berríos
@crisberrios
Feb 23 2015 03:46
start with 2, then apply lcm between the result and the 3rd item
it can be done using something like an array reduce function
as for determining LCM between 2 numbers, you better do a little research
because there are far more effective ways than just dividing the numbers and checking for the modulo
(prime factorization involved)
Danny Fritz
@dannyfritz
Feb 23 2015 05:22
heck yeah, got the cash register bonfire finished
Danny Fritz
@dannyfritz
Feb 23 2015 05:39
woot, every challenge is done
Cristián Berríos
@crisberrios
Feb 23 2015 05:49
:D
Matthew Harames
@Harames
Feb 23 2015 06:03
Hey guys why isn't this code working for the find the longest word challenge
function findLongestWord(str) {
  var test = str.split(" ");
  var now = null;
  for(var i = 0; i < test.length; i++) {
    if(test[i].length > now) {
      now = test[i];
    }
  }
  return now.length;
}

findLongestWord('The quick brown fox jumped over the lazy dog');
Cristián Berríos
@crisberrios
Feb 23 2015 06:06
start with now = 0;
and also, you assign test[i] to now
hmmm
no
with your approach
what you want to do is compare test[i].length agasint now.length
in that case, start with now = ""; (empty string)
Matthew Harames
@Harames
Feb 23 2015 06:08
@crisberrios Thanks this is the code that worked
function findLongestWord(str) {
  var test = str.split(" ");
  var now = "";
  for(var i = 0; i < test.length; i++) {
    if(test[i].length > now.length) {
      now = test[i];
    }
  }
  return now.length;
}

findLongestWord('The quick brown fox jumped over the lazy dog');
Cristián Berríos
@crisberrios
Feb 23 2015 06:09
:thumbsup:
Matthew Harames
@Harames
Feb 23 2015 06:25
OK I am obviously not very good at making javascript work. What is wrong with this Title Case a Sentence code.
function titleCase(str) {
  str = str.toLowerCase();
  var test2 = [];
  var test = str.split(" ");
  for(var i = 0; i < test.length; i++) {
    if(test[i].length === 1) {
      test2[i] = test[i].toUpperCase();
    } else {
      var split = test[i].split("");
      var upper = split[1].toUpperCase();
      var together = split.join("");
      test2[i] = together;
    }
  }
  test2 = test2.join(" ");
  return test2;
}

titleCase("I'm a little tea pot");
Nathan
@terakilobyte
Feb 23 2015 06:42
well...
do you need to test anything?
the str is coming in as a space separated sentence
here's an example using Ramda, which is now in bonfire and you can play with it
function titleCase(str) {
  return R.compose(R.join(' '), R.map(titleIt), R.split(' '), R.toLower)(str);
}

var titleIt = function titleIt(elem) {
  return elem[0].toUpperCase() + elem.slice(1).toLowerCase();
};
Ryan Malm
@Rybar
Feb 23 2015 07:04
@terakilobyte You have a moment to pair on an express bug?
Nathan
@terakilobyte
Feb 23 2015 09:28
@Rybar sorry was at work, home now
if you are still around and still have the bug
Alex Dixon
@alex-dixon
Feb 23 2015 11:23
        function flash (element) {
            var count = 0;
            return (function recursion () {
                setTimeout(
                    function () {
                    $(element).toggle();
                    count++;
                    if (count === 6) {
                        return true;
                    } else {
                        recursion();
                    }
                }, 300);
            }());
        }
return flash('.left-diagonal’);
this should stop everything while the animation runs then return true
instead the animation runs but it does not return true
Nathan
@terakilobyte
Feb 23 2015 11:41
@alex-dixon hmm
add a console log after you increment count
console.log(count)
Alex Dixon
@alex-dixon
Feb 23 2015 12:01
123456
@terakilobyte
Alex Dixon
@alex-dixon
Feb 23 2015 12:10
to be clear it does everything I’m looking for just not returning true
Oliver
@Dadsaster
Feb 23 2015 21:03
function destroyer(arr) {
  // Remove all the values
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Danny Fritz
@dannyfritz
Feb 23 2015 21:05
doesn't seem like you implemented it yet.
Oliver
@Dadsaster
Feb 23 2015 21:05
Shouldn't this return [1, 2, 3, 1, 2, 3], 2, 3 ?
Danny Fritz
@dannyfritz
Feb 23 2015 21:05
it should reutrn [1,1] i think
Oliver
@Dadsaster
Feb 23 2015 21:06
I know - I mean as currently written
Jon Lucas
@jonslucas
Feb 23 2015 21:06
right now it'll return [1,2,3,1,2,3]
iirc
Danny Fritz
@dannyfritz
Feb 23 2015 21:06
oh, that will return [1, 2, 3, 1, 2, 3]
Oliver
@Dadsaster
Feb 23 2015 21:06
how do I access the 2 and 3 values
?
Jon Lucas
@jonslucas
Feb 23 2015 21:06
arguments
Danny Fritz
@dannyfritz
Feb 23 2015 21:07
there is a special arguments variable injected into your function scope: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
Oliver
@Dadsaster
Feb 23 2015 21:08
Thank you very much - I was going crazy
Cristián Berríos
@crisberrios
Feb 23 2015 21:17
@Dadsaster take into account that arguments looks like an array, but it's not.
Evan Davis
@davisec52
Feb 23 2015 22:20
I'm working on the "Where Art Though" Bonfire challenge and don't understand why this is
failing. It appears to produce the required strings in repl.it.

function where(collection, source) {
  var arr = [];
  for(var i in source) {
    for(var j in collection) {
      if(collection.hasOwnProperty(j) === source.hasOwnProperty(i)) {
        arr[j] = collection[j];
      }
    }
  }
  return arr;
}
where([{ first: 'Romeo', last: 'Montague' }, { first: 'Mercutio', last: null }, { first: 'Tybalt', last: 'Capulet' }], { last: 'Capulet' });
Cristián Berríos
@crisberrios
Feb 23 2015 22:22
let's see
Evan Davis
@davisec52
Feb 23 2015 22:22
@crisberrios Hey, cris!
Cristián Berríos
@crisberrios
Feb 23 2015 22:23
hey
for(var j in collection) { if(collection.hasOwnProperty(j)
collection is an array of strings
so each "j" is an object
Evan Davis
@davisec52
Feb 23 2015 22:23
right
Cristián Berríos
@crisberrios
Feb 23 2015 22:24
and you are saying ("if collection has a property called {....} (the whole object)
that doesn't make sense
Evan Davis
@davisec52
Feb 23 2015 22:24
Wait, you are using for - in with collection
Oliver
@Dadsaster
Feb 23 2015 22:24
thaks @crisberrios and @dannyfritz - here is my solution if anyone has any suggestions on tightening it up
function destroyer(arr) {
  // Remove all the values
  var lister = arguments[0];
  for (var i = 1; i < arguments.length; i++) {
    var tester = arguments[i];
    for (var j = 0; j < arr.length; j++) {
      if (tester === lister[j]) {
        lister.splice(j,j+1);
      } 
    }
  }
  return lister;
}
destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3);
Evan Davis
@davisec52
Feb 23 2015 22:25
since collection is an array, though an array of objects, I thought you would still iterate as in for-loop.
Cristián Berríos
@crisberrios
Feb 23 2015 22:25
yeah, you iterate over the array, but not over the inner properties
@Dadsaster for (var i = 1; i < arguments.length; i++) { <--- repaeat after me: arguments is not an array
Oliver
@Dadsaster
Feb 23 2015 22:28
I know it isn't an array but it does return the length of arguments = is that a problem?
Cristián Berríos
@crisberrios
Feb 23 2015 22:29
hmm not really, but just in case, since you might be using it as an array property
but it's just coincidence that arguments has a length property
Oliver
@Dadsaster
Feb 23 2015 22:31
Assuming we don't know how many numbers are sent after arguments[0] how would you suggest avoid calling length on arguments?
Cristián Berríos
@crisberrios
Feb 23 2015 22:31
Eric Elliot makes great emphasis on checking arguments as an object and parsing them into an array before doing anything with them
Evan Davis
@davisec52
Feb 23 2015 22:31
This message was deleted
Cristián Berríos
@crisberrios
Feb 23 2015 22:31
but well... it works and it's not wrong, just one thing to be careful with
now... about the algorithm
Evan Davis
@davisec52
Feb 23 2015 22:32
@crisberrios My mistake. I put used a for-in statement instead of a for-loop.
Cristián Berríos
@crisberrios
Feb 23 2015 22:33
 for (var j = 0; j < arr.length; j++) {
      if (tester === lister[j]) {
        lister.splice(j,j+1);
      }
I might test what happens when you are testing for "2" in a an array like [1,2,2,3,4]
since you will be splicing the 1st 2
and lister[j+1] becomes lister[j]
so after you increase j
you will check 3
Oliver
@Dadsaster
Feb 23 2015 22:34
I see - good call
Cristián Berríos
@crisberrios
Feb 23 2015 22:34
and won't delete the 2nd 2
Oliver
@Dadsaster
Feb 23 2015 22:35
I actually does
however three 2's in a row and one is left - so it's still a good point
Cristián Berríos
@crisberrios
Feb 23 2015 22:36
I think that's also because of the 2nd parameter of splice
it should be the number of items to delete
not the ending item
let me confirm
yeah... 2nd parameter is delete amount
so it should always be 1 in this case
in the case of slice it's begin...end
Oliver
@Dadsaster
Feb 23 2015 22:38
I see that now - should be (j, 1)
Cristián Berríos
@crisberrios
Feb 23 2015 22:39
yep
Oliver
@Dadsaster
Feb 23 2015 22:39
I looked on mozilla and arguments does have a length property - but nothing else
Cristián Berríos
@crisberrios
Feb 23 2015 22:40
and the iteration jump, you can fix it by manually increasing it
for (var j = 0; j < arr.length; ) is valid
Oliver
@Dadsaster
Feb 23 2015 22:40
not sure how you mean?
Cristián Berríos
@crisberrios
Feb 23 2015 22:41
and you can then j++ based on the analysis
Oliver
@Dadsaster
Feb 23 2015 22:41
I see = move the j++ inside the for statement?
Cristián Berríos
@crisberrios
Feb 23 2015 22:41
yes, that would be one way
Oliver
@Dadsaster
Feb 23 2015 22:42
thanks - you're giving me a lot to think about.
Cristián Berríos
@crisberrios
Feb 23 2015 22:42
and if you want to make it much tighter...you can get rid of the loops and use arr.filter(....) instead
and also much tighter using Ramda (supported in bonfires) but that would be kind of "cheating" for learning purposes.
Oliver
@Dadsaster
Feb 23 2015 23:15
thanks for the filter tip - that will come in useful!
function destroyer(arr) {
    // Remove all the values
    var cleanArr = arr.filter(function(number) {
        if(arguments[1] === number || arguments[2] === number) {
                return false;
        } else {
            return true;
        }
    });
    return cleanArr;
}

destroyer([1, 2, 2, 3, 3, 4], 2, 3);
Cristián Berríos
@crisberrios
Feb 23 2015 23:49
the problem there is that only work for 2 arguments
but you're getting closer