These are chat archives for FreeCodeCamp/Help

15th
Oct 2017
Uriel Guzmán
@Burinson
Oct 15 2017 00:00
@moigithub
function whatIsInAName(collection, source) {
  // What's in a name?

  // Only change code below this line

    var ArrWithSource = collection.filter((function(objects){
      // Return the array that has the following condition:
      var sourceProp = source[Object.keys(source)];
      // Property of the source key in source args
      var sourceKey = [Object.keys(source)];
      // Key of the source value in collection args
      if (sourceProp != sourceKey) {
        return false;
      } else { return true;}
   return objects[sourceKey] === sourceProp; 
     // Filter the array where the requested property is equal to the one inside the source argument
})); 

    return ArrWithSource;
}
  // Only change code above this line  


whatIsInAName([{ "a": 1, "b": 2 },
               { "a": 1 }, 
               { "a": 1, "b": 2, "c": 2 }],
              { "a": 1, "b": 2 });
Kind of like this?
korzo
@korzo
Oct 15 2017 00:02
@Burinson source can have more than one key
Moisés Man
@moigithub
Oct 15 2017 00:02
u need aloop to check ALL sources properties, like the example above.....
Uriel Guzmán
@Burinson
Oct 15 2017 00:08
@moigithub Okay... a loop...
   function whatIsInAName(collection, source) {
  // What's in a name?

  // Only change code below this line

    var ArrWithSource = collection.filter((function(objects){
      // Return the array that has the following condition:
      var sourceProp = source[Object.keys(source)];
      // Property of source args
      var sourceKey = [Object.keys(source)];
      // Key of the source value in collection args
      var i = -1;
      while (i < sourceKey[0].length-1) {
        i++;
        return objects[sourceKey[0][i]] === sourceProp;


      }



     // Filter the array where the requested property is equal to the one inside the source argument
})); 

    return ArrWithSource;
}
  // Only change code above this line  


whatIsInAName([{ "a": 1, "b": 2 },
               { "a": 1 }, 
               { "a": 1, "b": 2, "c": 2 }],
              { "a": 1, "b": 2 });
Moisés Man
@moigithub
Oct 15 2017 00:16
its NOT ONLY a loop.. re-READ the pseudocode above...
knight2
@knight2
Oct 15 2017 00:18
@Burinson why do you have a return statement inside a while loop?
Uriel Guzmán
@Burinson
Oct 15 2017 00:18
I'm getting so stressed
knight2
@knight2
Oct 15 2017 00:19
putting a return statement inside a while loop will immediately execute the loop and not go through any more increments
Perhaps you are looking to return if you hit a certain value?
Uriel Guzmán
@Burinson
Oct 15 2017 00:20
@moigithub I literally don't even understand anymore
Kyle Holm
@thekholm80
Oct 15 2017 00:21
@DarrenfJ ty sir
CamperBot
@camperbot
Oct 15 2017 00:21
thekholm80 sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2133 | @darrenfj |http://www.freecodecamp.com/darrenfj
Georgia
@georgiawang5332
Oct 15 2017 04:34
@moigithub thank you XD
CamperBot
@camperbot
Oct 15 2017 04:34
georgiawang5332 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3671 | @moigithub |http://www.freecodecamp.com/moigithub
Eric Miller
@ericmiller777
Oct 15 2017 04:39
@DarrenfJ thanks
CamperBot
@camperbot
Oct 15 2017 04:39
ericmiller777 sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2134 | @darrenfj |http://www.freecodecamp.com/darrenfj
Manish Giri
@Manish-Giri
Oct 15 2017 06:52
@heroiczero @daddycardona @DarrenfJ @thekholm80 ty
CamperBot
@camperbot
Oct 15 2017 06:52
manish-giri sends brownie points to @heroiczero and @daddycardona and @darrenfj and @thekholm80 :sparkles: :thumbsup: :sparkles:
:cookie: 390 | @daddycardona |http://www.freecodecamp.com/daddycardona
:star2: 1509 | @thekholm80 |http://www.freecodecamp.com/thekholm80
:star2: 1882 | @heroiczero |http://www.freecodecamp.com/heroiczero
:star2: 2135 | @darrenfj |http://www.freecodecamp.com/darrenfj
Stephen
@TeddyHugs
Oct 15 2017 06:52
Hey all!
Manish Giri
@Manish-Giri
Oct 15 2017 06:53
@TeddyHugs buddy
@TeddyHugs ty
CamperBot
@camperbot
Oct 15 2017 06:53
manish-giri sends brownie points to @teddyhugs :sparkles: :thumbsup: :sparkles:
:cookie: 327 | @teddyhugs |http://www.freecodecamp.com/teddyhugs
Stephen
@TeddyHugs
Oct 15 2017 06:53
@Manish-Giri ty
Manish Giri
@Manish-Giri
Oct 15 2017 06:53
how's it going
Stephen
@TeddyHugs
Oct 15 2017 06:53
It's okay. And you? :D
I've been too busy with new projects at work >_<
Not fun at all
Manish Giri
@Manish-Giri
Oct 15 2017 06:53
lol
fun times
Stephen
@TeddyHugs
Oct 15 2017 06:53
@Manish-Giri thank you for that xD
CamperBot
@camperbot
Oct 15 2017 06:53
teddyhugs sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6653 | @manish-giri |http://www.freecodecamp.com/manish-giri
heroiczero
@heroiczero
Oct 15 2017 09:43
@daddycardona @DarrenfJ @thekholm80 ty @Manish-Giri
CamperBot
@camperbot
Oct 15 2017 09:43
heroiczero sends brownie points to @daddycardona and @darrenfj and @thekholm80 and @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 1510 | @thekholm80 |http://www.freecodecamp.com/thekholm80
:cookie: 391 | @daddycardona |http://www.freecodecamp.com/daddycardona
:star2: 2136 | @darrenfj |http://www.freecodecamp.com/darrenfj
:star2: 6654 | @manish-giri |http://www.freecodecamp.com/manish-giri
Jalaj
@TheVip
Oct 15 2017 10:24
Hiiii
rscales02
@rscales02
Oct 15 2017 10:28
So I am stuck in a bit of a sticky situation, trying to make a person by myself (ba dum cha!) and I don't fully understand the error I am getting.
var Person = function(firstAndLast) {
    var name = firstAndLast;
    this.getFullName = function() {
      return "name";
    };
    this.getLastName = function() {
      name = name.split(" ");
      return name[1];
    };
    this.getFirstName = function() {
      name = name.split(" ");
      return name[0];
    };
    this.setFirstName = function(str) {
      name.split(" ");
      name[0] = str;
      name.join(" ");
      return name;
    };
    return firstAndLast;
};

var bob = new Person('Bob Ross');
bob.setFirstName(dan); //returns error at this line saying "dan is not defined"
bob.getFullName();
Pethaf
@Pethaf
Oct 15 2017 10:30
@rscales02 You are trying to pass a variable called dan that doesn't exist.
I guess what you want is bob.setFirstName("dan")
rscales02
@rscales02
Oct 15 2017 10:31
stupid little details :smile: thanks @Pethaf
CamperBot
@camperbot
Oct 15 2017 10:31
rscales02 sends brownie points to @pethaf :sparkles: :thumbsup: :sparkles:
:cookie: 427 | @pethaf |http://www.freecodecamp.com/pethaf
rscales02
@rscales02
Oct 15 2017 10:37
with that fixed, if I just run bob.setFirstName("dan") it returns "dan ross" but then when I run bob.getFullName() immediately after it returns name any idea why?
Henry
@GitHub-Henry
Oct 15 2017 10:45
@DarrenfJ hello, and ty for the brownies
CamperBot
@camperbot
Oct 15 2017 10:45
github-henry sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2137 | @darrenfj |http://www.freecodecamp.com/darrenfj
Marc
@MWBauer
Oct 15 2017 15:04
Is there a way to auto-size a box around the random text that will be displayed?
Marc
@MWBauer
Oct 15 2017 17:14
I've been looking for a way to autosize the message that I'm going to display.
What do I need to do?
knight2
@knight2
Oct 15 2017 17:41
@rscales02 did you even look at the fuction you are complaiing about?
this.getFullName = function() { return "name"; };
Maybe because it literally returns "name" every time?
remove the "name" and change it to return your variable.
Marc
@MWBauer
Oct 15 2017 18:11
Hey guys
girls...
Stephen James
@sjames1958gm
Oct 15 2017 18:30
@MWBauer :wave:
@MWBauer If you don't give it height or width it should size to content (plus padding)
Uriel Guzmán
@Burinson
Oct 15 2017 20:07
How do you return only the true statements in a for loop?
Ex true, false, true
Only return the first and third result
alpox
@alpox
Oct 15 2017 20:08
@Burinson if you return inside of a loop, you leave the loop instantly. Instead, collext the data inside of the loop and return after it.
Uriel Guzmán
@Burinson
Oct 15 2017 20:08
Storing it in a variable?
And calling it outside of the loop?
alpox
@alpox
Oct 15 2017 20:09
Store it in a variable, yes. You cannot call a variable though, you can only call functions.
You can return the contents of a variable from a function though - which i meant to do after the loop
Uriel Guzmán
@Burinson
Oct 15 2017 20:10
@alpox Mind giving me an example? Thanks
CamperBot
@camperbot
Oct 15 2017 20:10
burinson sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1361 | @alpox |http://www.freecodecamp.com/alpox
Uriel Guzmán
@Burinson
Oct 15 2017 20:10
An example where you call the var from a function
alpox
@alpox
Oct 15 2017 20:12
@Burinson thats exactly what you cannot do. You cannot call a variable. You can only call functions.
Uriel Guzmán
@Burinson
Oct 15 2017 20:12
Well, an example where you return the contents of a variable from a function
alpox
@alpox
Oct 15 2017 20:12
@Burinson
function foo() {
    return 5;
}
foo(); // Function call
function foo() {
    var bar = "baz";
    return bar;
}
Here i return the contents of the variable bar from the function foo
This function can be used as follows:
var newVar = foo();
console.log(newVar);
This logs baz
Uriel Guzmán
@Burinson
Oct 15 2017 20:14
Interesting, let me try a sex
sec*
Uriel Guzmán
@Burinson
Oct 15 2017 20:27
@alpox
function whatIsInAName(collection, source) {

    var ArrWithSource = collection.filter((function(objects){

      for (var i = 0; i < [Object.keys(source)][0].length; i++) {
       // For checking each source property
      var sourceKey = [Object.keys(source)];
      // Key of the source arguments. Ex: a, b
        var sourceProp = source[sourceKey[0][i]];
        // Property of source args. Ex: source.a = 1

      console.log(objects[sourceKey[0][i]] === sourceProp);
        // Filter the array where the requested property is equal to the one inside the source argument

        }     
})); 

    return ArrWithSource;

}

whatIsInAName([{ "a": 1, "b": 2 },
               { "a": 1 }, 
               { "a": 1, "b": 2, "c": 2 }],
              { "a": 1, "b": 2 });
Should I store objects[sourceKey[0][i]] === sourceProp inside a variable
And make a function before the for loop?
alpox
@alpox
Oct 15 2017 20:29
@Burinson Oh... multiple things here. Let me explore
@Burinson 1. Thing: [Object.keys(source)][0] is totally redundant. Its the same as just: Object.keys(source)
Uriel Guzmán
@Burinson
Oct 15 2017 20:29
Yep, I'm stuck since yesterday with this one
alpox
@alpox
Oct 15 2017 20:30
Then, var sourceKey = [Object.keys(source)]; that sure does not give you a key, it gives you an array with one element - another array which holds all keys of the source.
I believe what you were going for is: Object.keys(source)[i] to get the key at index i
Whereas the actual property would be in source[sourceKey]
Ofc. you get the right sourceProp with your code too, but you make a long way around :D
Uriel Guzmán
@Burinson
Oct 15 2017 20:33
function whatIsInAName(collection, source) {

    var ArrWithSource = collection.filter((function(objects){

      for (var i = 0; i < [Object.keys(source)].length; i++) {
       // For checking each source property
      var sourceKey = [Object.keys(source)[i]];
      // Key of the source arguments. Ex: a, b
        var sourceProp = source[sourceKey[0][i]];
        // Property of source args. Ex: source.a = 1

      console.log(source[sourceKey]);
        // Filter the array where the requested property is equal to the one inside the source argument

        }     
})); 

    return ArrWithSource;

}

whatIsInAName([{ "a": 1, "b": 2 },
               { "a": 1 }, 
               { "a": 1, "b": 2, "c": 2 }],
              { "a": 1, "b": 2 });
Like this?
alpox
@alpox
Oct 15 2017 20:34
@Burinson Not exactly :-) why do you make [] around Object.keys(source)?
Uriel Guzmán
@Burinson
Oct 15 2017 20:34
Hm...
I barely noticed that
Hehehe
alpox
@alpox
Oct 15 2017 20:35

If you do:

var foo = [1, 2, 3, 4];
var bar = [foo];

What is the value of bar?

Uriel Guzmán
@Burinson
Oct 15 2017 20:35
[[1,2,3,4]]?
alpox
@alpox
Oct 15 2017 20:35
yep
Uriel Guzmán
@Burinson
Oct 15 2017 20:35
Oh, nice
alpox
@alpox
Oct 15 2017 20:35
So you just wrap an array into an array
Uriel Guzmán
@Burinson
Oct 15 2017 20:36
I think I copied it from somewhere in my code and forgot to remove them
alpox
@alpox
Oct 15 2017 20:36
You did the same thing with Object.keys(source) so you always needed to go through [0]
Uriel Guzmán
@Burinson
Oct 15 2017 20:36
So if you remove the brackets, you don't need [0] anymore?
alpox
@alpox
Oct 15 2017 20:36
Actually in this case though, you can just return from inside of the for - because if you found the attribute, you can stop searching
But i don't remember the exact question of that challenge anymore
@Burinson Yes, exactly
Uriel Guzmán
@Burinson
Oct 15 2017 20:37
It's like if I'm creating an array just to seach inside it again
LOl
alpox
@alpox
Oct 15 2017 20:37
If you access in my example the 3 how would you access it?
@Burinson Yea exactly thats what you did ;-)
Uriel Guzmán
@Burinson
Oct 15 2017 20:38
I guess bar[0][2]?
alpox
@alpox
Oct 15 2017 20:38
:thumbsup:
Uriel Guzmán
@Burinson
Oct 15 2017 20:38
You're really helpful
Let me see
alpox
@alpox
Oct 15 2017 20:39

so if you would instead do:

var bar = foo; // Without the []

you could do:

bar[2]

Directly

Uriel Guzmán
@Burinson
Oct 15 2017 20:42
@alpox
function whatIsInAName(collection, source) {

    var ArrWithSource = collection.filter((function(objects){

      for (var i = 0; i < Object.keys(source).length; i++) {
       // For checking each source property
      var sourceKey = Object.keys(source)[i];
      // Key of the source arguments. Ex: a, b
        var sourceProp = source[sourceKey];
        // Property of source args. Ex: source.a = 1

      console.log(objects[sourceKey] === sourceProp);
        // Filter the array where the requested property is equal to the one inside the source argument

        }     
})); 

    return ArrWithSource;

}

whatIsInAName([{ "a": 1, "b": 2 },
               { "a": 1 }, 
               { "a": 1, "b": 2, "c": 2 }],
              { "a": 1, "b": 2 });
alpox
@alpox
Oct 15 2017 20:42
@Burinson Looks much cleaner :D
Uriel Guzmán
@Burinson
Oct 15 2017 20:42
Yep :)
alpox
@alpox
Oct 15 2017 20:43
Now, what was the question of the challenge?
Uriel Guzmán
@Burinson
Oct 15 2017 20:43
Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching property and value pairs (second argument). Each property and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array.
It returns "true, false, true", and that's correct, it should only return the first and third array
Now I need a way of returning those arrays
alpox
@alpox
Oct 15 2017 20:44
@Burinson Okay then. Because of Each property and value pair of the source object has to be present in the object you have to loop through all of the source properties before you can tell if they are all there or not.
Uriel Guzmán
@Burinson
Oct 15 2017 20:45
Hm...
alpox
@alpox
Oct 15 2017 20:46
So you have to make a variable before the loop to "collect", or you return inside of the loop in a false case and return true after the loop.
That are two possibilities
  1. one looks about like:
    var everyIsTrue = true;
    for(...) {
     if(...) {
         everyIsTrue = false;
     }
    }
    return everyIsTrue;
second one looks about like:
for(...) {
    if(...) {
        return false;
    }
}
return true;
Same outcome, second one performs better
I hope you see whats going on :D
Moisés Man
@moigithub
Oct 15 2017 20:48

...looks pretty much the same i wrote yesterday :P

one way

loop on all sources
        if (source prop !== collection prop)
                 return false;   //one prop dont match
return true; //all matches

anther way is using .every method

alpox
@alpox
Oct 15 2017 20:49
@moigithub Yup :D pretty much xD
I was also almost going to tell about .every but i newcomers have hard times with such things :D
Uriel Guzmán
@Burinson
Oct 15 2017 20:50
@alpox
function whatIsInAName(collection, source) {

    var ArrWithSource = collection.filter((function(objects){

      for (var i = 0; i < Object.keys(source).length; i++) {
       // For checking each source property
      var sourceKey = Object.keys(source)[i];
      // Key of the source arguments. Ex: a, b
        var sourceProp = source[sourceKey];
        // Property of source args. Ex: source.a = 1

      if (objects[sourceKey] != sourceProp) {return false;}
        // Filter the array where the requested property is equal to the one inside the source argument

        }   return true;  
})); 

    return ArrWithSource;

}

whatIsInAName([{ "a": 1, "b": 2 },
               { "a": 1 }, 
               { "a": 1, "b": 2, "c": 2 }],
              { "a": 1, "b": 2 });
It worked!
alpox
@alpox
Oct 15 2017 20:50
@Burinson :thumbsup:
Uriel Guzmán
@Burinson
Oct 15 2017 20:51
@moigithub Thanks, but I didn't understand what was going on yesterday
CamperBot
@camperbot
Oct 15 2017 20:51
burinson sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3672 | @moigithub |http://www.freecodecamp.com/moigithub
alpox
@alpox
Oct 15 2017 20:51
@Burinson I hope you see whats going on with it now :D
Uriel Guzmán
@Burinson
Oct 15 2017 20:51
I needed a more detailed explanation