Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Dan Logajan
@hiltydiggs
@JackEdwardLyons I'm just going to put my whole solution out so that I can hopefully learn what's wrong with my approach from others. But it passes all tests.
function whereAreYou(collection, source) {
  var arr = [];
  // Only change code below this line
  var testKeys = Object.keys(source),
      rqrd = testKeys.length,
      collectionLength = collection.length,
      i,
      j,
      matched,
      currentKey,
      currentItem;

  for (i = 0; i < collectionLength; i++) {
    matched = 0;
    currentItem = collection[i];

    for (j = 0; j < rqrd; j++) {
      currentKey = testKeys[j];
      if (currentItem.hasOwnProperty(currentKey) && currentItem[currentKey] === source[currentKey]) {
        matched++;
      }
    }
    if (matched === rqrd) {
      arr.push(currentItem);
    }
  }
  // Only change code above this line
  return arr;
}

whereAreYou([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "c": 2 });
Stephen James
@sjames1958gm
@JackEdwardLyons you are pushing an object literal which is valid
DuskyPixel
@DuskyPixel
@JackEdwardLyons try arr.push(testValue);
Bailey
@coder7215
Yikes. You all probably think I'm crazy . . . :P
Oh! Because the COLUMN will only change the HORIZONTAL size . . . so how do I change the VERTICAL size? Can Bootstrap do that?
Jack Lyons
@JackEdwardLyons
i get this arr.push({ testKey : testValue} );
i thought I wanted to push the key and the value?
DuskyPixel
@DuskyPixel
what lesson are you on?
Dan Logajan
@hiltydiggs
Bailey
@coder7215
Ah! I think I got it!
:)
Dan Logajan
@hiltydiggs
@JackEdwardLyons you want to push the whole object if it contains all key/values in the source object.
Jack Lyons
@JackEdwardLyons
yeah
so wouldnt i do testKey + testValue ? @hiltydiggs
Dan Logajan
@hiltydiggs
@JackEdwardLyons look at my solution above and see if you can deconstruct it. I lead you down a slightly wrong path originally, I believe.
Chidders
@Chidders
for the "build a tribute page" am i supposed to already know how to build it by heart or is it ok to go back to my cat app for reference
Dan Logajan
@hiltydiggs
@Chidders you can use all the reference and documentation you want.
Julie
@jurijuri
@Chidders I go back to my earlier pages all the time :)
Chidders
@Chidders
oh alright thanks i didn't want to be cheating myself
Jack Lyons
@JackEdwardLyons
wow ok... looks complicated @hiltydiggs why did you make a variable called rqrd..whats that stand for
actually, nah it looks ok.. thanks
but wondering why you named that variable
Dan Logajan
@hiltydiggs
@JackEdwardLyons storing the length in a variable is more efficient in a for loop because the loop doesn't need to re-look up the length property of the array every time through the loop. It's a tiny efficiency, but just practicing best-practices I guess. rqrd stands for required in this case and I named it that because it's the number of matches required for the object to match the test case.
@JackEdwardLyons like I said, there's probably a much better way to do this challenge. I was hoping somebody else would provide insight.
Jack Lyons
@JackEdwardLyons
nah, i get it now... just takes me a loooong time to understand the logic... i want to be able to write these scripts from scratch but find it soo damn hard to do
Dan Logajan
@hiltydiggs
I'm know for sure it will start to make more sense to you as long as you keep at it. It's definitely frustrating at times, but if it was easy we wouldn't get paid!
Jack Lyons
@JackEdwardLyons
in this case does matched ++ mean that it will add new objects? i thought it was only reserved for numbers?
@hiltydiggs
Dan Logajan
@hiltydiggs
matched is a value that starts at 0 each time through the i loop. If the conditions in the if statement are met, matched++ adds one to the value of matched.
The currentItem.hasOwnProperty part was unnecessary.
function whereAreYou(collection, source) {
  var arr = [];
  // Only change code below this line
  var testKeys = Object.keys(source),
      rqrd = testKeys.length,
      collectionLength = collection.length,
      i,
      j,
      matched,
      currentKey,
      currentItem;

  for (i = 0; i < collectionLength; i++) {
    matched = 0;
    currentItem = collection[i];

    for (j = 0; j < rqrd; j++) {
      currentKey = testKeys[j];
      if (currentItem[currentKey] === source[currentKey]) {
        matched++;
      }
    }
    if (matched === rqrd) {
      arr.push(currentItem);
    }
  }
  // Only change code above this line
  return arr;
}

whereAreYou([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "c": 2 });
Gabriel Alexandre
@GabrielShaad
Hello world! I am developing my Portfolio page and I have an issue with the navbar. When it is small, the list of links becomes vertical, but I want it horizontal, like when it is in a big screen. How can I do it?
http://codepen.io/gabrielshaad/pen/BzLRdm?editors=1100
CamperBot
@camperbot

welcome to FreeCodeCamp @GabrielShaad!

Gabriel Alexandre
@GabrielShaad
Oh, and it is also overlapping the website.
I tried modifying the padding of the body like it is mentioned in the Bootstrap documentation, but it seems it failed.
Jack Lyons
@JackEdwardLyons
hey im wondering why my console.log in the nested loop isn't working?

function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];

  /* Set variables */
  var sourceKey = Object.keys(source); // create array for source key
  console.log(sourceKey);

  var testKey = Object.keys(source)[0]; // show source key as string
  console.log(testKey);

  var testValue = source[testKey]; // show source value as string
  console.log(testValue);


for ( var i = 0; i < collection.length; i++ ) {
    var collectedItems = collection[i];

  for (var j = 0; j < source.length; j++ ) {
    if ( collection[i].hasOwnProperty(sourceKey[j]) ) {
      console.log("hellllllllooooo?");
    }
  }  
}

  return arr;
}

whereAreYou([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Dan Logajan
@hiltydiggs
@JackEdwardLyons I see it. source is an object, so it doesn't have a length property.
Jack Lyons
@JackEdwardLyons
ah ok
so...
Dan Logajan
@hiltydiggs
you could use sourceKey.length
Islam Ibakaev
@dagman
@JackEdwardLyons what about this :smile:
function whereAreYou(first, second){
  var cond = JSON.stringify(second).slice(1, -1).split(',');
  console.log(cond);
  return first
  .map(function(el) {
    return JSON.stringify(el);
  })
  .filter(function(el) {
      for(var condition of cond) {
          if(!el.includes(condition)) return false;
      }
      return true;
  })
  .map(function(el) {
      return JSON.parse(el);
  });
}
@JackEdwardLyons have just made it for u
Jack Lyons
@JackEdwardLyons
haha my eyes just glaze over that code
thanks @dagman
CamperBot
@camperbot
jackedwardlyons sends brownie points to @dagman :sparkles: :thumbsup: :sparkles:
:cookie: 586 | @dagman |http://www.freecodecamp.com/dagman
Jack Lyons
@JackEdwardLyons
but i have no idea whats going
Islam Ibakaev
@dagman
@JackEdwardLyons it is not hard at all
Jack Lyons
@JackEdwardLyons
so you slice away the brackets on source ?
Islam Ibakaev
@dagman
@JackEdwardLyons yep
Jack Lyons
@JackEdwardLyons
then return first right away? why?