These are chat archives for FreeCodeCamp/HelpJavaScript

4th
Aug 2017
Margaret
@Margaret2
Aug 04 2017 00:13
@EgnaroDevDanke test
CamperBot
@camperbot
Aug 04 2017 00:13
margaret2 sends brownie points to @egnarodevdanke :sparkles: :thumbsup: :sparkles:
:cookie: 542 | @egnarodevdanke |http://www.freecodecamp.com/egnarodevdanke
Margaret
@Margaret2
Aug 04 2017 00:13
ahahaha it sends brownie points every time he's tagged :laughing:
@Manish-Giri ^
korzo
@korzo
Aug 04 2017 00:15
@Margaret2 It's the same if you have in your username gracia :)
CamperBot
@camperbot
Aug 04 2017 00:15
korzo sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 2864 | @margaret2 |http://www.freecodecamp.com/margaret2
Margaret2 @Margaret2 hurries to make new account
CallMeOrange
@EgnaroDev
Aug 04 2017 00:26
@Margaret2 :trollface:
Coy Sanders
@coymeetsworld
Aug 04 2017 00:37
wow thats killer
out of all the people that have been here for the last few years no one put thanks in their name
Manish Giri
@Manish-Giri
Aug 04 2017 01:01
@Margaret2 :tiger:
Luis Felipe López G.
@luishendrix92
Aug 04 2017 01:25
dat new name tho
let's bring the clojure hyptrain to this room :trollface:
Gurpreet SIngh
@Gurpreet3131
Aug 04 2017 02:06
How to identify user when using passportjs for ndoejs express login system
??
like after login, when I do any task, I want to identify who the user is
Moisés Man
@moigithub
Aug 04 2017 02:07
scotch.io have tutorial using passport
Gurpreet SIngh
@Gurpreet3131
Aug 04 2017 02:08
well i am looking for how to use session with passport
like I am able to build a login system. But i dont know how to identify a user even after the login the done
Moisés Man
@moigithub
Aug 04 2017 02:08
passport populates a req.user object with user info (IF u read the tutorialor passport documentation)
Gurpreet SIngh
@Gurpreet3131
Aug 04 2017 02:09
I think it can be done using sessions, but not sure how
passport.use(new LocalStrategy({
        usernameField: 'email'
    },
  function(username, password, done) 
  {
      userInfo.getUserByEmail(username, function(err, user)
      {
          if(err) throw err;
          if(!user)
          {
              return done(null, false, {message: 'Unknown user'});
          }

          userInfo.comparePassword(password, user.password, function(err, isMatch)
          {
              if(err) throw err;
              if(isMatch)
              {
                  return done(null, user);
              }
              else
              {
                  return done(null, false, {message: 'Invalid Password'});
              }
          });
      });  
  }
));


passport.serializeUser(function(user, done) {
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
  userInfo.getUserById(id, function(err, user) {
    done(err, user);
  });
});

router.post('/login',
    passport.authenticate('local', {successRedirect: '/', failureRedirect:'/users/login', failureFlash: true}),
      function(req, res)
    {
        console.log("this = " + req.user);
        res.redirect('/');
    }
);
this is my code. Now how can I get the info from the session
Moisés Man
@moigithub
Aug 04 2017 02:11
.. u already have it on req.user
if u wanna pass to client.. then create another endpoint ie: /userinfo
and send data to client router.get('/userinfo', (req,res)=>res.json(req.user) )
Gurpreet SIngh
@Gurpreet3131
Aug 04 2017 02:13
I want to use this info in another router file
Moisés Man
@moigithub
Aug 04 2017 02:13
req.user is available on server side anywhere....
Gurpreet SIngh
@Gurpreet3131
Aug 04 2017 02:14
so i can use req.user anywhere
@moigithub it worked. thanks a lot
CamperBot
@camperbot
Aug 04 2017 02:15
gurpreet3131 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3553 | @moigithub |http://www.freecodecamp.com/moigithub
Jacoby Clarke
@Jacobycodes18
Aug 04 2017 02:18
does anyone know of any good material to replicate the functionality of this scrolling technique?
Gurpreet SIngh
@Gurpreet3131
Aug 04 2017 02:20
when I open a webpage, I am storing the starttime in database, and when the webpage closes or changes, I want to store the endtime in the database. How can i check if webpage is closed or not?
Abhishek Tiwari
@fillopfy
Aug 04 2017 02:40
function truthCheck(collection, pre) {
  // Is everyone being true?
   var arr=[false,"",NaN,undefined,0,null];var c=false;
  for(var i=0;i<collection.length;i++)
    {
      if(collection[i].hasOwnProperty(pre)&&(arr.indexOf(collection[i][pre]===-1)))
        c=true;

    }
  return c;
}
what is wrong with my code
Adam Faraj
@adamfaraj
Aug 04 2017 02:43
@fillopfy try deleting the last parenthesis after [pre]===-1
Joseph
@revisualize
Aug 04 2017 02:43
@fillopfy Boolean()
Adam Faraj
@adamfaraj
Aug 04 2017 02:43
dont' quote me on that. i'm a few malt beverages in
Joseph
@revisualize
Aug 04 2017 02:44
The ()s are fine
Adam Faraj
@adamfaraj
Aug 04 2017 02:44
@revisualize ok. that last ) threw me off
Abhishek Tiwari
@fillopfy
Aug 04 2017 02:45
@adamfaraj if i remove the last parenthesis, it will be syntax error
@revisualize i just want to check for falsy values, how boolean?
Joseph
@revisualize
Aug 04 2017 02:52
@fillopfy did you look up Boolean() ?
Abhishek Tiwari
@fillopfy
Aug 04 2017 02:52
@revisualize no,should I compare it with boolean() instead of falsy array
Joseph
@revisualize
Aug 04 2017 02:55
@fillopfy Try it?
Jose Antonio Rivas
@joseantonio
Aug 04 2017 03:02
@revisualize hello
Abhishek Tiwari
@fillopfy
Aug 04 2017 03:07
function truthCheck(collection, pre) {
  // Is everyone being true?
   var arr=[NaN,false,"",undefined,0,null];var c=true;
  for(var i=0;i<collection.length;i++)
    {
      if(!collection[i].hasOwnProperty(pre)||(arr.indexOf(collection[i][pre])>0))
        c=false;

    }
  return c;
}

truthCheck([{"single": "double"}, {"single": NaN}], "single");
truthCheck([{"single": "double"}, {"single": NaN}], "single"); -returns true
truthCheck([{"single": "double"}, {"single": 0}], "single"); - returns false whyy???
Z.G.Hao
@akidox
Aug 04 2017 03:08
I am making a Ajex call to FCC’s weather API, but could not able to pass geoLocation info (as an array) to it, don’t know what the problem is.
here is my code:
$(document).ready(function() {
  function geoLocation () {
    var loc = [];
    if(navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        loc.push(position.coords.latitude);
        loc.push(position.coords.longitude);
      });
    }
    return loc;
  }
  function getWeather (arr) {
    var weat = {};
    //var weatherAPI = "https://api.openweathermap.org/data/2.5/weather?lat=" + arr[0] + "&lon=" + arr[1] + "&APPID=82cd5779d83e0531bab51bd1c31216b8";
    if (arr) {
      var weatherAPI = "https://fcc-weather-api.glitch.me/api/current?lat=" + arr[0] + "&lon=" + arr[1];
      $.getJSON(weatherAPI, function(json) {
        console.log(JSON.stringify(json));
      });
    }
  }
  $("#test").on("click", function(){
    var geo = geoLocation();
    getWeather(geo);
  });
});
Error message is this:
XHR finished loading: GET "https://fcc-weather-api.glitch.me/api/current?lat=undefined&lon=undefined".
Nick Gray
@nicholasnbg
Aug 04 2017 03:15

hey guys having a strange problem while doing the simon game project.

In one of my functions I'm wanting to check the players sequence of colors against the computers choices. Eg
player = ['red','blue','green'];
comp = ['red','blue','yellow'];

My problem is using if(player == comp) is returning false, when it should be true.

running

console.log(turnArray);
    console.log(checkComp);
    console.log(turnArray == checkComp);

returns
Array [ "green" ]
Array [ "green" ]
false

very confused as to how it returns false
Manish Giri
@Manish-Giri
Aug 04 2017 03:21
@nicholasnbg you can't compare values in two different arrays with equals operator
that just checks if the references to the two array objects are the same
lemme post an example
let arr1 = [1,2,3];
let arr2 = arr1;

console.log(arr1 == arr2);
console.log(arr1 === arr2);
both these will return true
because arr2 and arr1 refer/point to the same array object
but if you do
let arr3 = [1,2,3];
let arr4 = [1,2,3];

console.log(arr3 == arr4);
console.log(arr3 === arr4);
this prints false
even tho both arrays have the same elements/values
they are two different objects, stored at 2 different memory locations
Nick Gray
@nicholasnbg
Aug 04 2017 03:35
ahh ok, that makes sense, so is a loop the best way to check each entry then?
thanks for clearing that up @Manish-Giri
CamperBot
@camperbot
Aug 04 2017 03:35
nicholasnbg sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6365 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Aug 04 2017 03:36
@nicholasnbg you can use a loop
altho using external libraries is faster
Ogundele Olumide
@Lumexralph
Aug 04 2017 03:39
@Manish-Giri glad to find you here
@Manish-Giri how're you? need to ask some questions about setting up a database
Manish Giri
@Manish-Giri
Aug 04 2017 03:39

@nicholasnbg like I used _.isEqual from the library I linked -

let arr3 = [1,2,3];
let arr4 = [1,2,3];

console.log(_.isEqual(arr3, arr4));

this prints true, which is exactly what you want

@Lumexralph heyy bro, long time
how's the preparation going
Ogundele Olumide
@Lumexralph
Aug 04 2017 03:41
@Manish-Giri yes been a while, it's on bro, building at the database level of the app sgggggggm :smiling_imp:
Kelechi Chinaka
@ke1echi
Aug 04 2017 03:41
:wave: @Lumexralph
nice to see you
hows it going at the bootcamp @Lumexralph
Joseph
@revisualize
Aug 04 2017 03:45
@Manish-Giri Thanks.
CamperBot
@camperbot
Aug 04 2017 03:45
revisualize sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6366 | @manish-giri |http://www.freecodecamp.com/manish-giri
Ogundele Olumide
@Lumexralph
Aug 04 2017 03:45
@kelechy brotherly no be beans NodeJS, TDD, building an API presently.... those guys sha
Joseph
@revisualize
Aug 04 2017 03:46
@Manish-Giri How do you do that without using underscore.js?
Kelechi Chinaka
@ke1echi
Aug 04 2017 03:47
wow, nawa o @Lumexralph
Luis Felipe López G.
@luishendrix92
Aug 04 2017 03:47
ez
first check is equal length
second check is linear equality
Manish Giri
@Manish-Giri
Aug 04 2017 03:48
@revisualize
console.log(arr3.every((e, i) => arr4.indexOf(e) === i) && arr3.length === arr4.length);
Luis Felipe López G.
@luishendrix92
Aug 04 2017 03:49
given a tuple aa and a tuple bb, they are are equal if a1=b1a_{1} = b_{1} and a2=b2a_{2} = b_{2}
Ogundele Olumide
@Lumexralph
Aug 04 2017 03:49
@kelechy as in ehn.... my hand dey ache, but what i'll suggest is keep checking the bootcamp curriculum to know what you need to learn
Nick Gray
@nicholasnbg
Aug 04 2017 03:49
@Manish-Giri thanks for the tip on that library, will have to have a look through everything in there!
CamperBot
@camperbot
Aug 04 2017 03:49
nicholasnbg sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:warning: nicholasnbg already gave manish-giri points
Luis Felipe López G.
@luishendrix92
Aug 04 2017 03:49
repeating this binary comparison can yield your result
Ogundele Olumide
@Lumexralph
Aug 04 2017 03:49
@luishendrix92 in Python true
Luis Felipe López G.
@luishendrix92
Aug 04 2017 03:50
the length shoudl be the first check
Joseph
@revisualize
Aug 04 2017 03:50
@Manish-Giri Would it be faster to do the length compare before the other to fail faster?
Luis Felipe López G.
@luishendrix92
Aug 04 2017 03:50
it makes sense
Joseph
@revisualize
Aug 04 2017 03:50
@Manish-Giri or are both conditions evaluated even with the && ?
Kelechi Chinaka
@ke1echi
Aug 04 2017 03:50
where is the curriculum @Lumexralph
so i need prep well if i wan go there? @Lumexralph
Manish Giri
@Manish-Giri
Aug 04 2017 03:52
@revisualize idk
Luis Felipe López G.
@luishendrix92
Aug 04 2017 03:52

makes even more sense in a language without much visual clutter

list_equality a b = length a == length b and linear_equality a b
  where
    linear_equality [] [] = true
    linear_equality (x:xs) (y:ys) = x == y and linear_equality xs ys

or

linear_equality [] [] = true
linear_equality (x:xs) (y:ys) =
  if x == y then true and linear_equality xs ys else false
Manish Giri
@Manish-Giri
Aug 04 2017 03:52
why don't you run some tests to find out? @revisualize
Luis Felipe López G.
@luishendrix92
Aug 04 2017 03:52
and no, it's not haskell, it's something I pulled out of my butt that resembles haskell haha
(altho haskell has list equality built in by default, given its immutable nature)
Kelechi Chinaka
@ke1echi
Aug 04 2017 03:54
function removeZeros(array) {
  var nonZero = [], zeros = [];
  for (var i = 0; i < array.length; i++) {
    (+array[i] === 0) ? zeros.push(array[i]) : nonZero.push(array[i]);
  }
  return [...nonZero, ...zeros];
}
two questions
  1. how do i push to an array if all array methods are disabled for this challenge?
Luis Felipe López G.
@luishendrix92
Aug 04 2017 03:58
@kelechy methods disabled?
you can cheat and use Array.prototype.push.call
or, [...xs, x]
it will perform a concatenation, not really a push
tho
or you can do it the tricky way:
xs[xs.length] = newItem
Manish Giri
@Manish-Giri
Aug 04 2017 03:59
@kelechy you can do
array[array.length] = newItem
Luis Felipe López G.
@luishendrix92
Aug 04 2017 03:59
xs being the array of things
Manish Giri
@Manish-Giri
Aug 04 2017 03:59
oh right not -1
Luis Felipe López G.
@luishendrix92
Aug 04 2017 03:59
@Manish-Giri that will replace the last item and if the array is at least length 1
haha
yeah
Kelechi Chinaka
@ke1echi
Aug 04 2017 04:02
ok
quick one
function filter(array) {
  var  newArray = [];
  for (var i = 0; i <= array.length; i++) {
    if (array[i] > 3) {
      newArray.push(array[i]);
    }
  }
  return newArray;
}
trying to implement a filter method and i am getting undefined..what am i doing wrong?
Luis Felipe López G.
@luishendrix92
Aug 04 2017 04:03
what's that function supposed to do anyway
lol
there's nothing wrong with it
it works
filter([1,2,3,4,5])
(2) [4, 5]
Kelechi Chinaka
@ke1echi
Aug 04 2017 04:04
then something is wrong with the test cases
Luis Felipe López G.
@luishendrix92
Aug 04 2017 04:05
well, you didn't say it was a test
lol
Manish Giri
@Manish-Giri
Aug 04 2017 04:05
lol
Luis Felipe López G.
@luishendrix92
Aug 04 2017 04:05
the function as you wrote is ok
Manish Giri
@Manish-Giri
Aug 04 2017 04:05
for (var i = 0; i <= array.length; i++)
here
should probably be <
Luis Felipe López G.
@luishendrix92
Aug 04 2017 04:05
except that it only purges values inferior to 4
Manish Giri
@Manish-Giri
Aug 04 2017 04:05
not <=
check
Luis Felipe López G.
@luishendrix92
Aug 04 2017 04:05
oh yeah that too
I hate for loops so I never read what's inside
Kelechi Chinaka
@ke1echi
Aug 04 2017 04:06
i still dont understand what u mean by array[array.length] = new array @Manish-Giri @luishendrix92
no its a CW kata :smile:
Luis Felipe López G.
@luishendrix92
Aug 04 2017 04:06

well imagine you have

[1,2,3]

index 0 = 1, index 1 = 2 and index 2 = 3

Manish Giri
@Manish-Giri
Aug 04 2017 04:06
it means, create a new position in the array
Luis Felipe López G.
@luishendrix92
Aug 04 2017 04:06
what's the next index?
Manish Giri
@Manish-Giri
Aug 04 2017 04:06
which is guaranteed to be the last
and insert there
Luis Felipe López G.
@luishendrix92
Aug 04 2017 04:07
the next index is 3
which happens to be the current length of the array
so you're setting a value to the last position at the last index + 1
you're basically saying, I want the element number 4 (index 3, since arrays and 0-based index) to be something
after then = sign
Kelechi Chinaka
@ke1echi
Aug 04 2017 04:11
it keeps jamming ma head, the logic still not clear
Kelechi Chinaka
@ke1echi
Aug 04 2017 04:16
i would let it slip in a bit so it can make sense
Coy Sanders
@coymeetsworld
Aug 04 2017 05:34
The way I read it once that made sense was that index represented how far away the element was from the beginning of the array
so the first index is 0 because it's 0 away from the first element (i.e. itself), second index is 1 because its one to the right of the first element, etc
Markus Kiili
@Masd925
Aug 04 2017 05:36
@kelechy You should note that creating new array elements with arr[i] = ... can cause arrays with holes (evil). Array methods are safer in that sense. arr[arr.length] = ... is safe though.
Gurpreet SIngh
@Gurpreet3131
Aug 04 2017 06:27
{{#if user}}
              <li role="presentation"><a href="/">Index</a></li>
              {{admin}}
                <li role="presentation"><a href="/adminPanel/adminRegister">Register</a></li>
                <li role="presentation"><a href="/users/insert">Insert</a></li>
              {{/admin}}
              <li role="presentation"><a href="/users/logout">Logout</a></li>

            {{else}}
              <li role="presentation"><a href="/users/login">Login</a></li>
              <li role="presentation"><a href="/users/register">Register</a></li>
            {{/if}}
I have a part of code in hadlebars which I only want the admin to see after he registers
the 2 list items between the admin tag
How can I make it specific to admin login??
Matej Bošnjak
@mbosnjak01
Aug 04 2017 06:31
Hi eveneryone. Alright so ... I have a function that takes an array and ID of an html element to display data. Array contains several links to JSON data, so ... my function iterates through that array and displays values from each link. ... Those values are fixed inside function ... now, I need those values as an function parameter like function (array, container, desiredValueToCall) ... My issue is, when I set it like this, I get nothing displayed (This is non working func http://i.imgur.com/6fvT1II.png) ... This is working one http://i.imgur.com/aT9tivs.png ... am just struggling on how to pass that options as parameters like in first function so I could call it like this: function(array, 'option', container)
Pieter Stokkink
@forkerino
Aug 04 2017 06:37
@mbosnjak01 on my phone, so cannot really explain at length, but one issue is that you can't use dot notation for variables. So array[opt] would be better.
Markus Kiili
@Masd925
Aug 04 2017 06:39
@mbosnjak01 In other words, array.opt for example looks for property key "opt", not the key stored in parameter opt.
The bracket notation instead evaluates the expression inside the brackets into a string, so array[opt] would use the property key stored in opt.
kumquatfelafel
@kumquatfelafel
Aug 04 2017 06:42
Going along with this... :point_up:
var someObj = {
  'opt' : 'Hello',
  'sandwich' : 'world'
} 

var opt = 'sandwich';
console.log(someObj.opt); // outputs Hello
console.log(someObj[opt]); //outputs world
Brian Montellano
@bmontellano
Aug 04 2017 06:45
you can also define as an object, array = {}
then set a key/value pair for the object array.opt = 'yourvaluehere' .
Assuming array is an array, you can't treat said array as an obj, but as Pieter Stokkink pointed out, you can user opt to point out the index of the array, as array[opt].
Markus Kiili
@Masd925
Aug 04 2017 06:48
@bmontellano Arrays are objects, so you can add properties to arrays as you like, but plain objects are better and clearer for that purpose.
kumquatfelafel
@kumquatfelafel
Aug 04 2017 06:48
You can treat an array like an object since an array is an object. That being said, it doesn't necessarily mean that doing something like array['opt'] = "hello"; is a good idea
Matej Bošnjak
@mbosnjak01
Aug 04 2017 06:57
@kumquatfelafel @Masd925 @bmontellano @Masd925 @forkerino Got my thing working, finally! Thank you guys :)
CamperBot
@camperbot
Aug 04 2017 06:57
mbosnjak01 sends brownie points to @kumquatfelafel and @masd925 and @bmontellano and @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 565 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:cookie: 206 | @bmontellano |http://www.freecodecamp.com/bmontellano
:star2: 2916 | @forkerino |http://www.freecodecamp.com/forkerino
:star2: 4377 | @masd925 |http://www.freecodecamp.com/masd925
kumquatfelafel
@kumquatfelafel
Aug 04 2017 07:13

@bmontellano Though yeah, here's what happens when you play around with array ;)

https://repl.it/Jwjh/8

iso
@iso1048
Aug 04 2017 07:44

function sumFibs(num) {

  var arr = [1,1];

  for (var i = 2; i<=num; i+=arr[arr.length-2]){
    arr.push(i);
  }
  arr = arr.filter(function(val){return val%2 !==0;}).reduce(function(a,b){return a+b;});
  return arr;
}

sumFibs(6);
what is a better way to do the challenge?
Markus Kiili
@Masd925
Aug 04 2017 07:52
@gothamknight That loop is somewhat hard to read. Another more efficient way is to just generate the fibos without storing them on an array. Your solution is quite standard and fine too.
Tiago Correia
@tiagocorreiaalmeida
Aug 04 2017 07:52
good morning everyone
Markus Kiili
@Masd925
Aug 04 2017 07:53
@tiagocorreiaalmeida Morning.
Tiago Correia
@tiagocorreiaalmeida
Aug 04 2017 07:53
im doing the tic tac toe exercise is it a good idea use the bootstrap grid for it? usign 3 col-md-4 for each space
iso
@iso1048
Aug 04 2017 07:54
@Masd925 ok thanks
CamperBot
@camperbot
Aug 04 2017 07:54
gothamknight sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4378 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Aug 04 2017 07:54
@tiagocorreiaalmeida Sounds like a fine idea.
Tiago Correia
@tiagocorreiaalmeida
Aug 04 2017 07:55
but seems like a stupid idea have to remove at almost every number a part of their border
just saw a better idea eheh
王龙
@magiclalala
Aug 04 2017 09:08
why the result of[ var myStr="This is the start."+"This is the end."; ]has a string name.I can not pass this lasson
lesson
kumquatfelafel
@kumquatfelafel
Aug 04 2017 09:09
If I had to guess (don't quite remember the challenge), you may need a space between start. and This

@magiclalala yep. You need a space after start.

So resulting string would be like This is the start. This is the end. as opposed to what you have, which is This is the start.This is the end.

王龙
@magiclalala
Aug 04 2017 09:12
thanks,that's helpful
Chris Juchtmans
@kjuchtmans
Aug 04 2017 09:25
morning to you all, fine coders of netherworld ! :wave:

"Record Collection"
Why is below code Repl.it link replacing the elements in array "tracks", and not adding at the end?
This solutions seems to be accepted by FCC, yet when I test it here the "Tracks" array is not storing previously added elements

cheers, k

Jim Tryon
@jimtryon
Aug 04 2017 09:46
Can you see where I went wrong in this function?
function every(arr) {
    foreach (element in arr) {
        var value = false;
        if (element == true) 
            value = true;
        else 
            value = false;
    }
    return value;
}
Jim Tryon
@jimtryon
Aug 04 2017 09:49
I was trying to use a foreach
I wrote my own solution to this problem but the previous lesson was on the .reduce method so I don’t know if that would have been the efficient solution.
eeflores
@eeflores
Aug 04 2017 09:51
looks like it's a function of Array, so it'll be something like arr.forEach(function(element) {
Jim Tryon
@jimtryon
Aug 04 2017 09:52
that is me coming from Java
no wonder I didn’t notice that foreach is deprecated
eeflores
@eeflores
Aug 04 2017 09:52
Other type of for is for (var elem in arr) {
Jim Tryon
@jimtryon
Aug 04 2017 09:52
So you can do it with a for
Markus Kiili
@Masd925
Aug 04 2017 09:52
@jimtryon forEach is not deprecated.
eeflores
@eeflores
Aug 04 2017 09:52
foreach is deprecated where?
Jim Tryon
@jimtryon
Aug 04 2017 09:53
I was just told it was deprecated.
for each has been deprecated. Array now has it's own forEach method
https://devdocs.io/javascript/global_objects/array/foreach
eeflores
@eeflores
Aug 04 2017 09:54
for each not Array.forEach
didn't find "deprecated" in the link
Akhona
@AkhonaNcols
Aug 04 2017 09:55
i need help on using += operator
Markus Kiili
@Masd925
Aug 04 2017 09:56
@jimtryon for each...in loop was in the language at some point. Not to be confused with Array.prototype.forEach or for...in loop.
kumquatfelafel
@kumquatfelafel
Aug 04 2017 09:56
@kjuchtmans I'm not entirely sure what the problem is you're having??? https://repl.it/Jwrc/1
It seems to be storing tracks fine to me.
Jim Tryon
@jimtryon
Aug 04 2017 09:56
So which one should I use? .foreach or for?
heroiczero
@heroiczero
Aug 04 2017 09:56
@AkhonaNcols += is a operator that adds and stores it like var i += 2 will add 2 and store in i
@jimtryon for your current situation for
Jim Tryon
@jimtryon
Aug 04 2017 09:58
function every(arr) {
    for (element in arr) {
        var value = false;
        if (element === true) 
            value = true;
    }
    return value;
}
I cleaned up the code a bit
It’s still failing
kumquatfelafel
@kumquatfelafel
Aug 04 2017 09:59
@heroiczero you don't want to say var i += 2; though.
Markus Kiili
@Masd925
Aug 04 2017 10:00
@jimtryon If you use for...in loop on an array, it iterates over the property keys, not over array elements. So element there will have values like "0" and "1" etc.
Jim Tryon
@jimtryon
Aug 04 2017 10:00
@Masd925 So I should use .foreachthen?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:00
@jimtryon It seems like your flag is messed up since it keeps getting overwritten.
Jim Tryon
@jimtryon
Aug 04 2017 10:00
Or add more code to cover the for loop on an array
Markus Kiili
@Masd925
Aug 04 2017 10:00
For looping over array indices, you should use a simple for loop, not for...in. Array iterators like forEach can also be used.
eeflores
@eeflores
Aug 04 2017 10:01
@jimtryon one thing about Array.forEach that I read: you can't terminate the loop early
Markus Kiili
@Masd925
Aug 04 2017 10:01
@jimtryon
Jim Tryon
@jimtryon
Aug 04 2017 10:01
I’m trying to model the for each loop which I think is more elegant than for
I don’t know how many agree with that, always preferred for each
eeflores
@eeflores
Aug 04 2017 10:02
actually according to MDN you can break out of forEach with an exception, but that's not polite
Markus Kiili
@Masd925
Aug 04 2017 10:03
@eeflores Also would be confusing to the reader.
Jim Tryon
@jimtryon
Aug 04 2017 10:03
so let me ask another question, should I worry about elegance in my code or just use something that is functional?
ex. my preference of for each vs for
eeflores
@eeflores
Aug 04 2017 10:03
something that is readable
mithun
@dmithun
Aug 04 2017 10:04
function mutation(arr) {
var x = arr.toLowerCase();
return x.indexOf(0)===x.indexOf(1);
}
mutation(["hello", "hey"]);
eeflores
@eeflores
Aug 04 2017 10:04
something that can be easy to decipher quickly?
Markus Kiili
@Masd925
Aug 04 2017 10:04
@jimtryon Clarity of the code is usually most important. Efficiency and code length also have some value depending on the case.
mithun
@dmithun
Aug 04 2017 10:04
why toLowerCase method isn't working????????
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:04
@dmithun You can't call toLowerCase on an array. toLowerCase is a string function.
Jim Tryon
@jimtryon
Aug 04 2017 10:04
It’s not a black and white area from what I see then
@Masd925
Markus Kiili
@Masd925
Aug 04 2017 10:06
@jimtryon No. Most choices have two sides. More elegant is less efficient in many cases.
eeflores
@eeflores
Aug 04 2017 10:06
toLowerCase is a function of String, not Array
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:06
@dmithun Also, the arguments you're passing into indexOf are no good.
Jim Tryon
@jimtryon
Aug 04 2017 10:06
So this passed all of the tests except for 2
function every(arr) {
    for (var i = 0; i < arr.length; i++) {
        var value = false;
        if (arr[i] === true) 
            value = true;
    }
    return value;
}
I changed it to a for loop
eeflores
@eeflores
Aug 04 2017 10:07
value is always being reset to false, so it'll be whatever the last iteration was
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:07
@jimtryon value is overwritten with false after each iteration of the loop. This code is weird.
eeflores
@eeflores
Aug 04 2017 10:07
possibly initialise value outside looop
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:07
agreed
eeflores
@eeflores
Aug 04 2017 10:07
that's loooooooooooop
mithun
@dmithun
Aug 04 2017 10:08
@kumquatfelafel what should i do now????
eeflores
@eeflores
Aug 04 2017 10:08
yeah reduce could do the same as the for I think ...
Jim Tryon
@jimtryon
Aug 04 2017 10:08
I’m wondering if my whole solution is not the best… the lesson was over .reduce, I didn’t know how to use .reduce in my code
So I wrote my own solution
eeflores
@eeflores
Aug 04 2017 10:09
@jimtryon another thing you could do in your loop is break once value has been set to true
Jim Tryon
@jimtryon
Aug 04 2017 10:09
@eeflores How does reduce work?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:09
@dmithun dunno. I dunno what you've done. :p
Go along with instructions and try to solve. ;)
mithun
@dmithun
Aug 04 2017 10:10
ok :V
:v
eeflores
@eeflores
Aug 04 2017 10:10
@jimtryon I haven't really worked with reduce, if I tried something it would be a solution. Is that OK?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:10
@jimtryon Could you link to this by the way? Don't want to give bad advice here. :p
Jim Tryon
@jimtryon
Aug 04 2017 10:11
@eeflores Yeah, that would be ok. I’d link to it @kumquatfelafel except it’s for the curriculum in our coding bootcamp that I’m going through to help the students.
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:11
ah. gotcha
Jim Tryon
@jimtryon
Aug 04 2017 10:11
But I want to understand it so I can be of more help to them
A lot of them are confused as all hell about these higher order functions
eeflores
@eeflores
Aug 04 2017 10:12
@jimtryon ok let's see ... something like
arr.reduce(function(acc, curr) {
  return acc || curr;
}, false);
@jimtryon lemme check the docs
Jim Tryon
@jimtryon
Aug 04 2017 10:13
Yeah, I remember reading there is a start and a combine
It’s not as straightforward as other methods
eeflores
@eeflores
Aug 04 2017 10:13
slight change ...
so the return value will be true (supposedly?) if any value in the array is true
Jim Tryon
@jimtryon
Aug 04 2017 10:15
Let me show you the tests
eeflores
@eeflores
Aug 04 2017 10:15
@jimtryon with what you're trying to do, it's not the most efficient method, because it will check all elements in the array, regardless if you've already found a true value or not
Jim Tryon
@jimtryon
Aug 04 2017 10:15
every([true, true, true, false]) // false
every([true, true, true, true])  // true
every([false, true, true])       // true
every([])                        // true
eeflores
@eeflores
Aug 04 2017 10:15
hmm that last test?
Jim Tryon
@jimtryon
Aug 04 2017 10:16
With the way I did it, it passed test #1, #2
eeflores
@eeflores
Aug 04 2017 10:16
oooohhh
Jim Tryon
@jimtryon
Aug 04 2017 10:16
Failed at test #3
eeflores
@eeflores
Aug 04 2017 10:16
hold on
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:16
If we're talking about the same (in concept) as Array.prototype.every(), then it should only return true if all the values are true
Jim Tryon
@jimtryon
Aug 04 2017 10:16
every is a function that should return true if every element in the array is true, false otherwise
if the array is empty, it should return true by default
eeflores
@eeflores
Aug 04 2017 10:17
@jimtryon you could pass that with arr.reduce(function(acc, curr){return curr;}, true);
@jimtryon that description doesn't match the third case
Jim Tryon
@jimtryon
Aug 04 2017 10:17
I want to understand how reduce works based off your code
What does reduce do exactly?
It looks similar to map which is essentially an iterator
eeflores
@eeflores
Aug 04 2017 10:18
it does iterate, but map returns a modified array, and reduce returns 1 value
some examples?
Jim Tryon
@jimtryon
Aug 04 2017 10:18
so map will return a collection
and reduce will return a single value?
eeflores
@eeflores
Aug 04 2017 10:19
yep
Markus Kiili
@Masd925
Aug 04 2017 10:19
@jimtryon It is the general array iterator, so a bit more complex than the others. You can set an initial value for the accumulator that is changed at each step of iteration. The callback function tells reduce how to get to the next accumulator value from the previous and the element being iterated.
Jim Tryon
@jimtryon
Aug 04 2017 10:19
ok, so will your code pass all 4 tests?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:19

@jimtryon It is like map in that it iterates though array and does something, but reduce "accumulates" a value instead.

A simple example would be like...

eeflores
@eeflores
Aug 04 2017 10:19
[1,2,3].reduce(function(acc, curr){return acc + curr;}, 0); should return 6
Jim Tryon
@jimtryon
Aug 04 2017 10:19
So acc = accumulator
and curr = current?
Markus Kiili
@Masd925
Aug 04 2017 10:20
@eeflores ,0 there is optional in that case.
eeflores
@eeflores
Aug 04 2017 10:20
[3,3,2].reduce(function(acc, curr){return acc * curr;}, 1); should return 18
yes
Jim Tryon
@jimtryon
Aug 04 2017 10:20
@kumquatfelafel there is the part I was not understanding, so it accumulates instead of just iterates
thanks @kumquatfelafel
CamperBot
@camperbot
Aug 04 2017 10:20
jimtryon sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 566 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Saikat-Sinha
@Saikat-Sinha
Aug 04 2017 10:20
guys is there any way to add superscript and subscript in input field?
Jim Tryon
@jimtryon
Aug 04 2017 10:21
so 3 * 3 * 2 = 18
Markus Kiili
@Masd925
Aug 04 2017 10:21
@Saikat-Sinha Where exactly do you mean?
eeflores
@eeflores
Aug 04 2017 10:21
yes, with an initial value of 1
or a slight modification to the last one: [3,3,2].reduce(function(acc, curr){return acc * curr;}, 2); should return 36, because the initial value is 2
Jim Tryon
@jimtryon
Aug 04 2017 10:22
so how would I use that with my for loop?
eeflores
@eeflores
Aug 04 2017 10:23
it would replace your for loop
Jim Tryon
@jimtryon
Aug 04 2017 10:23
function every(arr) {
    arr.reduce(function(start, combine) {
        var value = false;
        if (arr[i] === true) 
            value = true;
    }
    return value;
}
Something like that?
eeflores
@eeflores
Aug 04 2017 10:24
@jimtryon but just going back on that description of what you're trying to achieve, it doesn't hold true for test 3 as there is a false in the array and the expected value is true
Jim Tryon
@jimtryon
Aug 04 2017 10:24
Yeah, passing all the tests seems to be the major challenge for me
Also rewriting it to use reduce
heroiczero
@heroiczero
Aug 04 2017 10:24
you need a initial case for your reduce
eeflores
@eeflores
Aug 04 2017 10:25
@jimtryon the brace above the return is part of the reduce function, so it needs }, [initial value]);
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:25
@eeflores I'm operating off the hope/assumption that those commented values were not the expected value, but the result. :/
Jim Tryon
@jimtryon
Aug 04 2017 10:25
Well, I don’t need to accumulate anything if I’m just checking for boolean values
but I’m sure it could be still written with reduce
eeflores
@eeflores
Aug 04 2017 10:25
oh ok
oh so the logic of my example will need to be reversed ...
heroiczero
@heroiczero
Aug 04 2017 10:27
@jimtryon if your array is empty and it will be an error unless you have an initial value
Jim Tryon
@jimtryon
Aug 04 2017 10:27
So the initial value will go in the .reduce as one of the arguments
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:27

@jimtryon More like ...

arr.reduce((a,b) => a && b , true);

I think??? But not entirely sure 100% what you're attempting here.

eeflores
@eeflores
Aug 04 2017 10:28
@kumquatfelafel yep that looks good
Jim Tryon
@jimtryon
Aug 04 2017 10:28
I’m attempting to check these 4 tests
Example

every([true, true, true, false]) // false
every([true, true, true, true])  // true
every([false, true, true])       // true
every([])                        // true
Sample Input:
true true true false
Sample Output:
false
Anirudh
@anirudh708
Aug 04 2017 10:28
@anirudh708
Hi Everyone I am trying to use babel to transpile ES6 to ES5.
I am trying to see what all the things babel does not support. I came across this http://kangax.github.io/compat-table/es6/#test-arrow_functions_lexical_super_binding_in_constructors
But I could not understand many things in that. Example like it said babel does not support 'correct precedence' under arrow functions.
There was an example which also did not help me.
Can some one provide more starter friendly source to check what babel does not support.
heroiczero
@heroiczero
Aug 04 2017 10:30
@jimtryon that third case is confusing to me if it would be false && true and that would return false. Shouldn't it?
Jim Tryon
@jimtryon
Aug 04 2017 10:30
Yeah, I’ve been trying to work that out @heroiczero
I’m thinking it’s because most of the values are true
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:31
@jimtryon Is commented value the expected value, or your result?
Jim Tryon
@jimtryon
Aug 04 2017 10:31
That is the expected value
@kumquatfelafel
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:32
@jimtryon that sounds more like some() than every()
except, not some either.
eeflores
@eeflores
Aug 04 2017 10:32
then it would seem that the reduce return the last value in the array with an intialiser of true
Chris Juchtmans
@kjuchtmans
Aug 04 2017 10:32
@kumquatfelafel got it thanks. What I did was modifying parameters but calling the main function only once. What I notice you do, is calling it on multiple lines, each call setting new parameters. Then it holds all previous values fine. Thanks!
CamperBot
@camperbot
Aug 04 2017 10:32
kjuchtmans sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 567 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:33
@jimtryon Is there a verbal description regarding what this function should do?
Jim Tryon
@jimtryon
Aug 04 2017 10:33
This is the text from the lesson:

Write a function named every that has one parameter:

arr - an array of booleans
The function returns true if every element in the array is true, otherwise, it returns false. If the array is empty, it defaults to true.

codeolas
@codeolas
Aug 04 2017 10:33

Hey all, I get a weird error message on this code:

function flattener(a){

     var i = a.length;
    if(i === 0){
      return a;
    } else if(Array.isArray(a[i - 1])){
      return flattener(a[i-1][i - 1]);
    } 


  }

  flattener([3, [[4]]]);
TypeError: a is undefined
    at flattener:3:7
    at flattener:7:12
    at eval:13:1
`

Can anyone explain what's going on?

heroiczero
@heroiczero
Aug 04 2017 10:33
@jimtryon hmm that third case is wrong then i think
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:34
@heroiczero agreed.
The expected value for that test is incorrect.
Should expect false
heroiczero
@heroiczero
Aug 04 2017 10:34
maybe a bug?
eeflores
@eeflores
Aug 04 2017 10:34
@codeolas I think you can't do a.length on a number
Jim Tryon
@jimtryon
Aug 04 2017 10:34
I’ll have to make a comment on the submission
@kumquatfelafel @heroiczero
eeflores
@eeflores
Aug 04 2017 10:35
@codeolas should test that a is an array before doing a.length
codeolas
@codeolas
Aug 04 2017 10:36
@eeflores I tried typeof and it says it's an object. console.log(a.length); comes up with a value of 2.
Jim Tryon
@jimtryon
Aug 04 2017 10:37
@eeflores @kumquatfelafel This is my lead instructor’s solution:
function every(arr) {
    return arr.reduce(function (m, r) { return m && r; }, true);
}
eeflores
@eeflores
Aug 04 2017 10:37
@jimtryon yeah but that won't work for the 3rd array
@codeolas you just need to rearrange the code a little
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:38
@codeolas if a.length is 0, what does that mean?
EpicTriffid
@EpicTriffid
Aug 04 2017 10:38
Can anyone give me a better description of what I'm meant to be doing in this challenge? It makes no sense to me? https://www.freecodecamp.com/challenges/wherefore-art-thou
Jim Tryon
@jimtryon
Aug 04 2017 10:39
@eeflores I’m going to try it and see if it works
eeflores
@eeflores
Aug 04 2017 10:39
@codeolas:
function flattener(a) {
  if (Array.isArray(a) {
    // do array stuff
  } else {
    // do number stuff
  }
}
Frank
@Frankbono
Aug 04 2017 10:39
@Frankbono
Can someone tell me what I did wrong here. I am working on my weather app and so far I am able to get all the necessary info from the API but when it comes to putting the weather icon from the API, everything I tried doesn’t work. Can someone help me please
Here’s my code
https://codepen.io/Frankbono/pen/prNozW
codeolas
@codeolas
Aug 04 2017 10:40
@kumquatfelafel I'm working on the steamroller challenge. It's a work in progress, trying to do it with recursive functions. It's meant to be the base case, but this error is bugging me because I don't understand it.
@kumquatfelafel the error is before that, so I want to clear it and get back to setting up the function properly
heroiczero
@heroiczero
Aug 04 2017 10:41
@EpicTriffid you want to return all the property elements from the collection if collection[key]===source[key]
eeflores
@eeflores
Aug 04 2017 10:43
@kumquatfelafel I think a.length was making the assumption that int values have an array length of 0
EpicTriffid
@EpicTriffid
Aug 04 2017 10:43
@heroiczero Hmm, I'm still not following?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:43
:point_up: August 4, 2017 6:39 AM
@codeolas the base case would be when it is a number. Or rather, non-array value.
Jim Tryon
@jimtryon
Aug 04 2017 10:44
So this code passed all the tests @eeflores @kumquatfelafel
function every(arr)  {
  return arr.reduce((sum, element) => sum && element, true)
}
heroiczero
@heroiczero
Aug 04 2017 10:44
@Frankbono try https://openweathermap.org/weather-conditions you need a img
eeflores
@eeflores
Aug 04 2017 10:44
@jimtryon just out of interest, could you print the result of the 3rd array test?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:44
@eeflores seems like it.
eeflores
@eeflores
Aug 04 2017 10:45
@jimtryon I/we expect that the comment value won't equal what the function will return
Jim Tryon
@jimtryon
Aug 04 2017 10:47
Is that what you want me to do?
function every(arr)  {
  var result = arr.reduce((sum, element) => sum && element, true);
    console.log(result);
}
I can’t get that to pass the first test
eeflores
@eeflores
Aug 04 2017 10:47
something like that ...
but won't pass?
oh, should return result
codeolas
@codeolas
Aug 04 2017 10:48
@kumquatfelafel hmm. ok, that makes sense.
@eeflores sure, but I need to go in the array... And yes, i was thinking that numbers have an array length of 0. Probably wrong...
Jim Tryon
@jimtryon
Aug 04 2017 10:48
Failed test #1. Wrong answer
Input:
true true true false

Your output:
false
false
Correct output:
false
eeflores
@eeflores
Aug 04 2017 10:48
@codeolas good guess though, and now you'll remember!
Jim Tryon
@jimtryon
Aug 04 2017 10:48
@eeflores @kumquatfelafel
heroiczero
@heroiczero
Aug 04 2017 10:49
@EpicTriffid whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" }); in this example you want to return [{ first: "Tybalt", last: "Capulet" }] because source["last"] is the same as collection["last"]
eeflores
@eeflores
Aug 04 2017 10:49
@jimtryon looks like the console.log is affecting the tests
Jim Tryon
@jimtryon
Aug 04 2017 10:49
yeah, I’m trying to find a workaround
if I return, that passes all of the tests
eeflores
@eeflores
Aug 04 2017 10:50
@jimtryon based on the 3rd array, every([false, true, true]); should return false, but the comment shows true, that's all
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:51

@codeolas By the way, if you're wondering why, specifically you're getting that a is undefined error...

var i = [3, [[4]]].length (so 2)
Goes to else if, since length not 0...
a[2-1][2-1]... so a[1][1]

a[1] is [[4]].

Second element of [[4]] (a[1][1]) is undefined

Ergo, when you say

var i = a.length in second function call, you're now saying undefined.length so...

Jim Tryon
@jimtryon
Aug 04 2017 10:52
@eeflores I did it in the console for you guys
let arr = [“false”, “false”, “true”];
every(arr);
"true"
eeflores
@eeflores
Aug 04 2017 10:52
@codeolas you could paste your code into http://pythontutor.com/javascript.html#mode=edit to see how the values change
@jimtryon that's strange ...
Jim Tryon
@jimtryon
Aug 04 2017 10:53
I’m still trying to work out how they get true
Unless it’s because there is one `true’ value
eeflores
@eeflores
Aug 04 2017 10:53
@jimtryon I think it's because arr is declared let
Jim Tryon
@jimtryon
Aug 04 2017 10:53
So that makes the whole expression true
kumquatfelafel
@kumquatfelafel
Aug 04 2017 10:53
@jimtryon how what get's true?
eeflores
@eeflores
Aug 04 2017 10:53
@jimtryon try var arr = etc
Jim Tryon
@jimtryon
Aug 04 2017 10:54
Oh, that is with var arr=
var arr = ["false", "false", "true”];
arr
eeflores
@eeflores
Aug 04 2017 10:54
@jimtryon when you use let, it no longer is defined when every is called, you're actually passing an undefined value (I think)
Jim Tryon
@jimtryon
Aug 04 2017 10:54

arr
(3) ["false", "false", "true"]0: "false"1: "false"2: "true"length: 3__proto__: Array(0)
I pasted it worng @eeflores
I actually used var to declare that array
eeflores
@eeflores
Aug 04 2017 10:55
ok
codeolas
@codeolas
Aug 04 2017 10:55
@kumquatfelafel oh, yes, that's what I need really
@eeflores I know of pythontutor, it just doesn't work in my browser for some weird reason.
eeflores
@eeflores
Aug 04 2017 10:57
@jimtryon or maybe the values in the array shouldn't be strings?
@jimtryon should just be [false, true, true]
Jim Tryon
@jimtryon
Aug 04 2017 10:58
Oh, let me try that @eeflores
good catch, thanks @eeflores
CamperBot
@camperbot
Aug 04 2017 10:58
jimtryon sends brownie points to @eeflores :sparkles: :thumbsup: :sparkles:
:star2: 1010 | @eeflores |http://www.freecodecamp.com/eeflores
Jim Tryon
@jimtryon
Aug 04 2017 10:58
var newArr = [false, true, true];
undefined
every(newArr);
false
eeflores
@eeflores
Aug 04 2017 10:59
that makes sense
any questions about that @jimtryon ?
Jim Tryon
@jimtryon
Aug 04 2017 11:00
No, that should be false based on boolean logic, right?
eeflores
@eeflores
Aug 04 2017 11:00
yep, that's right
Jim Tryon
@jimtryon
Aug 04 2017 11:00
Since not every one is true, that makes it false
But that’s interesting
eeflores
@eeflores
Aug 04 2017 11:00
correctamundo!
Jim Tryon
@jimtryon
Aug 04 2017 11:00
because isn’t a true, false, still true?
eeflores
@eeflores
Aug 04 2017 11:01
do you mean true && false?
in that case true && false is false. Only true && true equal true
heroiczero
@heroiczero
Aug 04 2017 11:01
true || false is true
but true&& false is false
Jim Tryon
@jimtryon
Aug 04 2017 11:02
well are we saying && or || in this function?
I actually didn’t know
eeflores
@eeflores
Aug 04 2017 11:02
yeah we want && (and)
heroiczero
@heroiczero
Aug 04 2017 11:02
for every it is &&
eeflores
@eeflores
Aug 04 2017 11:02
good ol' boolean/bitwise operators
Jim Tryon
@jimtryon
Aug 04 2017 11:03
I’m going to look up .every in JS
since I’ve never seen it
eeflores
@eeflores
Aug 04 2017 11:04
@jimtryon that shorthand can be a bit of a stretch if you're not familiar with boolean operators
Jim Tryon
@jimtryon
Aug 04 2017 11:04
Return value
true if the callback function returns a truthy value for every array element; otherwise, false.
Stephen James
@sjames1958gm
Aug 04 2017 11:04
@Frankbono Your symbol variable IS the URL
$("#logo").html("<img class = 'newIcon' src=" + symbol + ">");
Jim Tryon
@jimtryon
Aug 04 2017 11:05
so basically I was writing a function that already exists
that is an interesting exercise
Stephen James
@sjames1958gm
Aug 04 2017 11:06
@jimtryon A difference is that .every will terminate on first falsey
Jim Tryon
@jimtryon
Aug 04 2017 11:06
Thanks @sjames1958gm @eeflores and @kumquatfelafel
CamperBot
@camperbot
Aug 04 2017 11:06
jimtryon sends brownie points to @sjames1958gm and @eeflores and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:warning: jimtryon already gave eeflores points
:warning: jimtryon already gave kumquatfelafel points
:star2: 8239 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Jim Tryon
@jimtryon
Aug 04 2017 11:07
I need to report that mistake
Frank
@Frankbono
Aug 04 2017 11:09
@sjames1958gm Thanks Stephen! It works now
Stephen James
@sjames1958gm
Aug 04 2017 11:10
@Frankbono :+1:
Jim Tryon
@jimtryon
Aug 04 2017 11:10
That is enough code for one night. Thanks everyone!
eeflores
@eeflores
Aug 04 2017 11:10
now, on to youtube binge watching!
Stephen James
@sjames1958gm
Aug 04 2017 11:11
@jimtryon :sleepy:
heroiczero
@heroiczero
Aug 04 2017 11:12
@jimtryon Good night :)
EpicTriffid
@EpicTriffid
Aug 04 2017 11:13
@heroiczero Right, That makes more sense. Thankyou!
CamperBot
@camperbot
Aug 04 2017 11:13
epictriffid sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1571 | @heroiczero |http://www.freecodecamp.com/heroiczero
kumquatfelafel
@kumquatfelafel
Aug 04 2017 11:18

@codeolas If you look at stack trace, you'll also notice it says

at flattener:3:7
at flattener:7:12
at eval:13:1

This basically tells you that error was thrown in flattener function line 3. This function in turn, was invoked by flattener function at line 7, which in turn was invoked in "eval" at line 13.

While this doesn't give a full picture, it does give some ideas. We can pretty much figure out just from looking at the stack trace (including error description) that we must be passing undefined as an argument to flattener in our recursive call, even if we're not entirely sure *why*.

from there, of course, the question becomes "why" ;)
Sergey
@zhukovsp
Aug 04 2017 11:24
Hey, guys! What am I missing? I use npm package (works with API) and I configure that package with api keys belong every user. I have two users for test now, but they are interrupting each other. 2nd user receive data belongs 1st user. How can I run npm package like private instance for each users?
Hills
@Hillsie
Aug 04 2017 11:25
I’m a little confussed by the this keyword. In python OO, you have the self keyword, which operates at the instance level. If you change a variable that is declared with self it only applies at the instance level, not the object. Is that how this works?
EpicTriffid
@EpicTriffid
Aug 04 2017 11:25
Im wondering, when running through a for loop, like below, can i just type "i", or do i have to type "collection[i]"?
 for (var i = 0; i <= collection.length; i++) {
    if (i.hasOwnProperty(source)) {
kumquatfelafel
@kumquatfelafel
Aug 04 2017 11:25
@EpicTriffid i is very different from collection[i].
i is a primitive (numeric) value.
EpicTriffid
@EpicTriffid
Aug 04 2017 11:26
@kumquatfelafel Would you be able to explain?
Stephen James
@sjames1958gm
Aug 04 2017 11:28
@EpicTriffid What is collection?
Hills
@Hillsie
Aug 04 2017 11:29
For instance, I’m looking at the make object Properties private and the code has var speed as a private variable. But isn’t this an object variable that if changed, changes at the object level, and not the instance level? …. guess I better go try it.
var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};
Stephen James
@sjames1958gm
Aug 04 2017 11:29
@kumquatfelafel I know, it was a leading question
@Hillsie When you call the constructor function with new you get a new context of execution and
a 'new' speed variable
kumquatfelafel
@kumquatfelafel
Aug 04 2017 11:31
@sjames1958gm gotcha. Giveaway answer deleted. ;)
Stephen James
@sjames1958gm
Aug 04 2017 11:31
@kumquatfelafel :)
codeolas
@codeolas
Aug 04 2017 11:31
@kumquatfelafel that is incredibly helpful. Never really understood what those error messages mean. :+1: I am now looking at the whole thing in pythontutor ( :+1: @eeflores ) to wrap my head around the function.
EpicTriffid
@EpicTriffid
Aug 04 2017 11:32
@sjames1958gm collection is an array of objects, right?
Stephen James
@sjames1958gm
Aug 04 2017 11:32
@EpicTriffid Yes, and how do you get the values from an array ?
Abhinav Mishra
@abhinav-m
Aug 04 2017 11:37
@sjames1958gm hello
do you remember the setState problem i was facing yesterday?
Stephen James
@sjames1958gm
Aug 04 2017 11:38
@abhinav-thinktank yes
Abhinav Mishra
@abhinav-m
Aug 04 2017 11:38
which was basically due to it's asynchronous nature
ok so to solve that, i have used callbacks which basically link one setState call to another
it has solved the problem, but im not sure if it's a good practice
im gonna post the pen here once im done with the whole project
Stephen James
@sjames1958gm
Aug 04 2017 11:40
@abhinav-thinktank I have never used that callback on setState
Abhinav Mishra
@abhinav-m
Aug 04 2017 11:40
@sjames1958gm oh
it's basically because i have two state objects who's property depends on each other
value* not property
Stephen James
@sjames1958gm
Aug 04 2017 11:42
@abhinav-thinktank ok, reading up on setState, the callback seems to be used for that condition.
Abhinav Mishra
@abhinav-m
Aug 04 2017 11:43
@sjames1958gm ok
ok i'll get it reviewed here once im done! @sjames1958gm thanks!
CamperBot
@camperbot
Aug 04 2017 11:43
abhinav-thinktank sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8240 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 04 2017 11:43
@abhinav-thinktank :+1:
Jatin Dahiya
@jdahiyajd
Aug 04 2017 11:47
freecodecamp chunky monkey not responsive page help?
EpicTriffid
@EpicTriffid
Aug 04 2017 11:54
@sjames1958gm I would have to cycle through the array using a for loop?
Blauelf
@Blauelf
Aug 04 2017 11:54
@jdahiyajd Add run=disabled to the URL to prevent it from executing the code on page load. Like https://www.freecodecamp.com/challenges/chunky-monkey?run=disabled
Stephen James
@sjames1958gm
Aug 04 2017 11:54
@EpicTriffid Yes, and to get the value from the array you have to use arr[i] or in this case collection[i]
Blauelf
@Blauelf
Aug 04 2017 11:55
@jdahiyajd Then fix your infinite loop and try again ;)
EpicTriffid
@EpicTriffid
Aug 04 2017 11:55
@sjames1958gm So why would "i" be a problem? Isn't "i" linked to the collection array?
Stephen James
@sjames1958gm
Aug 04 2017 11:56
@EpicTriffid Not really. i is just a number (it is only related to collection array in that the for loop limits the value to < collection.length)
EpicTriffid
@EpicTriffid
Aug 04 2017 11:58
@sjames1958gm So i is sort of free to loop anything, its just the statement you put within its function that dictates what its looping through?
Stephen James
@sjames1958gm
Aug 04 2017 11:59
@EpicTriffid yes
Hills
@Hillsie
Aug 04 2017 12:00
@sjames1958gm Thanks. I’m trying to figure out some commonality so I can remember. I guess, OOP is a little different in JS. I’ve seen some common stuff in ES6. Seems similar. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor
CamperBot
@camperbot
Aug 04 2017 12:00
hillsie sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8241 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 04 2017 12:01
@Hillsie the function constructor in a class is different than a function that can be a constructor like the one you showed above
Hills
@Hillsie
Aug 04 2017 12:02
@sjames1958gm I was just about to ask you that.
@sjames1958gm I’m obviously confused about the usage.
Frank
@Frankbono
Aug 04 2017 12:03
I’m working on my weather app and the weather icon isn’t showing anymore. It was showing before I added buttons so now I’m really confusing. I don’t know if it’s something I did or the API
here the code
Stephen James
@sjames1958gm
Aug 04 2017 12:04
@Frankbono Looks ok to me, the icon is there, for me
Darth Skywalker
@AdiSkywalker
Aug 04 2017 12:05
@Frankbono I, too, can see the icon
Frank
@Frankbono
Aug 04 2017 12:06
@sjames1958gm It’s not showing on my end. Could it be the API?
Stephen James
@sjames1958gm
Aug 04 2017 12:06
@Frankbono Check your devtools console - are you getting an error (did you save the pen before posting that link?
Frank
@Frankbono
Aug 04 2017 12:08
@sjames1958gm I did save it. I am getting an error
undefined:1 GET https://s.codepen.io/boomerang/iFrameKey-72c36108-48c4-1205-c64e-e7fe95f83753/undefined 404 ()
Stephen James
@sjames1958gm
Aug 04 2017 12:09
@Frankbono Must be the API is not giving an icon for your lat / long ??
@Frankbono Can you console.log the api variable and paste it here?
Looks like you didn't get an icon value in the response (that is why undefined
Frank
@Frankbono
Aug 04 2017 12:11
I put both var api & api in the console and I get back undefined
@sjames1958gm I put both var api & api in the console and I get back undefined
Stephen James
@sjames1958gm
Aug 04 2017 12:12
@Frankbono Your api variable should be the URL that you build from lat/long?
console.log(api) right before $.getJSON
Frank
@Frankbono
Aug 04 2017 12:15
@sjames1958gm Ok I did that and in the console I get the API and then followed by that error message that I got before
Stephen James
@sjames1958gm
Aug 04 2017 12:25
@Frankbono What is the value of api?
Stephen James
@sjames1958gm
Aug 04 2017 12:30
@Frankbono When I click on that and get the JSON, there is no icon in weather[0] that is why it is not showing.
Here is the weather property
"weather": [
{
"id": 520,
"main": "Rain",
"description": "light intensity shower rain"
},
{
"id": 701,
"main": "Mist",
"description": "mist",
"icon": "50d"
}
],
For my location:
"weather": [
{
"id": 701,
"main": "Mist",
"description": "mist",
"icon": "https://cdn.glitch.com/6e8889e5-7a72-48f0-a061-863548450de5%2F50d.png?1499366021771"
}
],
Looks like a problem with the API :(
Frank
@Frankbono
Aug 04 2017 12:30
@sjames1958gm So it is the API
Stephen James
@sjames1958gm
Aug 04 2017 12:30
@Frankbono yes
Frank
@Frankbono
Aug 04 2017 12:31
@sjames1958gm Thanks for helping me figure this out. I was really confused
CamperBot
@camperbot
Aug 04 2017 12:31
frankbono sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8242 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 04 2017 12:31
@Frankbono :+1:
Chris_Bo
@krzysztofbogusz91
Aug 04 2017 12:32
Hi any idea why this code won't update my arr 1 with new items?

function updateInventory(arr1, arr2) {


  for (i = 0;i <= arr1.length; i++){
    for (j = 0;j <=arr2.length;j++){
       if(arr1[i][1]!==arr2[j][1]){
       arr1.push(arr2[j]);

     }//end if
      return arr1;
    }//end j loop
  }//end i loop



}

// Example inventory lists
var curInv = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var newInv = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];

updateInventory(curInv, newInv);
Markus Kiili
@Masd925
Aug 04 2017 12:36
@krzysztofbogusz91 Returning inside the loop block like that terminates the loop on first iteration.
Usually you do stuffs inside the loop block and return after the loop.
Also mutating the array you iterate over with for messes up the indices.
Chris_Bo
@krzysztofbogusz91
Aug 04 2017 12:40
@Masd925 ok thanks! I will try with forEchach function now...
CamperBot
@camperbot
Aug 04 2017 12:40
krzysztofbogusz91 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4380 | @masd925 |http://www.freecodecamp.com/masd925
Kelechi Chinaka
@ke1echi
Aug 04 2017 12:42
any ideas where i can learn about bubble sort and the likes @sjames1958gm @Masd925
Markus Kiili
@Masd925
Aug 04 2017 12:43
@kelechy I watched Courcera Princeton algorithms course and it covered all the sorting algorithms.
Kelechi Chinaka
@ke1echi
Aug 04 2017 12:48
i'll check it out..thanks @Masd925
CamperBot
@camperbot
Aug 04 2017 12:48
kelechy sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4381 | @masd925 |http://www.freecodecamp.com/masd925
Simon Cordova
@gbsimon87
Aug 04 2017 12:52
Hey guys, good afternoon to everyone.
Need some help with regex if anyone has any experience...
I found a good page on stackoverflow but I'm unsure how to implement it, anyone could offer a hand?
Ene Catalin
@EneCatalin
Aug 04 2017 12:54
does the twitch project only need to have a few pre-selected channels ?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 12:55

bubble sort.... (assume ascending order)

1, 3, 0, 5, 4, 8, 7, 6

Compares 1 and 3. in order so no swap.
Compares 3 and 0. Out of order, ergo swap.
Compares 3 and 5. In order so no swap.
Compares 4 and 8. No swap.
...
Compares 8 and 6. Out of order, ergo swap.

now looks like...

1, 0, 3, 4, 5, 7, 6, 8

8, by definition, must be largest number in array at this point. However, can't say for certain whether other numbers are sorted. So we have to go through again (excluding 8)

Compares 1 and 0. Swap.

...

Compares 7 and 6. Swap.

And so on... until we know that array is fully sorted.

Ene Catalin
@EneCatalin
Aug 04 2017 12:56
bubble sort is also hated with a passion by some people
Abhinav Mishra
@abhinav-m
Aug 04 2017 12:57
bubble sort is awful
Ene Catalin
@EneCatalin
Aug 04 2017 12:57
that guy hates bubble sort
Abhinav Mishra
@abhinav-m
Aug 04 2017 12:57
^
Ene Catalin
@EneCatalin
Aug 04 2017 12:58
so anyway, twitch project, do I just need a few pre selected channels
or should the user be able to search any channel ?
Nick Gray
@nicholasnbg
Aug 04 2017 12:59
I think both @EneCatalin
kumquatfelafel
@kumquatfelafel
Aug 04 2017 12:59

In this case, you'd only have to iterate through it three times (twice to sort, then once to confirm no further swaps are necessary), but it could be a lot worse.

@EneCatalin @abhinav-thinktank bubble sort is a pretty straightforward sorting algorithm conceptually, but other than that... yeah, it's pretty awful. But, hey, at least it's not bogosort :p

Nick Gray
@nicholasnbg
Aug 04 2017 12:59
mine had a few as defualts, then the option to add more if you entered the streamer name
Abhinav Mishra
@abhinav-m
Aug 04 2017 13:01
@EneCatalin a few users
@EneCatalin however they should include a user who has deleted their account or something like that..
i can't remember exactly
so you need to handle the undefined response
kumquatfelafel
@kumquatfelafel
Aug 04 2017 13:02
@gbsimon87 What are you trying to do?
Simon Cordova
@gbsimon87
Aug 04 2017 13:10
Hey @kumquatfelafel I ended up figuring it out, cheers though I appreciate it
kumquatfelafel
@kumquatfelafel
Aug 04 2017 13:10
np
Jatin Dahiya
@jdahiyajd
Aug 04 2017 13:11
@Blauelf thanks , i was trying something odd but it got boom boom :)
CamperBot
@camperbot
Aug 04 2017 13:11
jdahiyajd sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4554 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Aug 04 2017 13:14

@jdahiyajd The run=disabled and other methods (like an infinite loop detection which checks how long your sample call takes, does not detect infinite loops that happen only in certain cases) got introduced because this is a somewhat common problem.

Earlier, one would have to edit/delete their localStorage, where the entered codes reside on your local computer (there are also copies of your last submissions for each challenge on the server, accessible via the profile).

Jatin Dahiya
@jdahiyajd
Aug 04 2017 13:19
@Blauelf until (run=disabled) i was not able to do, m trying to learn ty
CamperBot
@camperbot
Aug 04 2017 13:19
jdahiyajd sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:warning: jdahiyajd already gave blauelf points
makalohri
@makalohri
Aug 04 2017 13:21
@knrt10 Thank you
CamperBot
@camperbot
Aug 04 2017 13:21
makalohri sends brownie points to @knrt10 :sparkles: :thumbsup: :sparkles:
:cookie: 478 | @knrt10 |http://www.freecodecamp.com/knrt10
Jatin Dahiya
@jdahiyajd
Aug 04 2017 13:22
how to disable camper bot ?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 13:22
There's no particular need to do so.
Jatin Dahiya
@jdahiyajd
Aug 04 2017 13:22
everytime i thanks or mention it appears.
Blauelf
@Blauelf
Aug 04 2017 13:25

That's one of its remaining core functions. Previously it also could show hints for the various challenges.

There's even a project for creating a Brownie Point Leaderboard, with most brownie points originating from thanks.

Jatin Dahiya
@jdahiyajd
Aug 04 2017 13:25
so it will be there alll the time :)
gotcha
kumquatfelafel
@kumquatfelafel
Aug 04 2017 13:27
Find brownies
CamperBot
@camperbot
Aug 04 2017 13:27
find brownies
nothing found
kumquatfelafel @kumquatfelafel glares at CamperBot suspiciously.
Blauelf
@Blauelf
Aug 04 2017 13:28
The github wiki connection was probably disabled/removed when the wiki moved to the new forum.
kumquatfelafel
@kumquatfelafel
Aug 04 2017 13:29
@Blauelf What is this comment in reference to?
Blauelf
@Blauelf
Aug 04 2017 13:29
The find command, I think it used to find articles in the wiki, or in some other database.
kumquatfelafel
@kumquatfelafel
Aug 04 2017 13:29
ah
Ronique Ricketts
@RoniqueRicketts
Aug 04 2017 13:31
@Blauelf the brownie api don't seem live btw
kumquatfelafel
@kumquatfelafel
Aug 04 2017 13:32
@Blauelf I imagine camperbot must be heartbroken now that it's gone.
...
find happiness
CamperBot
@camperbot
Aug 04 2017 13:32
find happiness
nothing found
Blauelf
@Blauelf
Aug 04 2017 13:33
@RoniqueRicketts That's what I think, too. Probably a snapshot made manually.
Ronique Ricketts
@RoniqueRicketts
Aug 04 2017 13:34
@Blauelf oh I was thinking that it may update once or twice per year maybe.
Blauelf
@Blauelf
Aug 04 2017 13:35
Something like that.
EpicTriffid
@EpicTriffid
Aug 04 2017 13:39
Why do i keep getting, "cannot read property "hasOwnProperty" of undefined" with this code?

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

  for (var i = 0; i <= collection.length; i++) {
    if (collection[i].hasOwnProperty(source)) {
      arr.push(collection[i]);
    }
  }

  return arr;
}
Blauelf
@Blauelf
Aug 04 2017 13:40
gitter archives go back only about 18 months (January 13th, 2016), so old @camperbot behaviour is no longer present there. I think the big move away from waypoint, bonfire, zipline and basejump happened in late 2015 or so.
@EpicTriffid <= is the culprit. Use <.
EpicTriffid
@EpicTriffid
Aug 04 2017 13:41
@Blauelf Why does that cause a problem?
Blauelf
@Blauelf
Aug 04 2017 13:41
@EpicTriffid collection[collection.length] is undefined, and undefined has no properties by definition.
EpicTriffid
@EpicTriffid
Aug 04 2017 13:42
@Blauelf Im confused? Why is it undefined?
Blauelf
@Blauelf
Aug 04 2017 13:42
Valid indices range from zero to length minus one. That makes length different indices.
kumquatfelafel
@kumquatfelafel
Aug 04 2017 13:42
array indices starts at index 0. length = number of elements. So when there is 1 element in array, length = 1, and the first and only cell is array[0].
Blauelf
@Blauelf
Aug 04 2017 13:43
BTW, source is itself an object, not a string. You might want to use the array of strings gained from Object.keys(source), it's an array of property names.
Ronique Ricketts
@RoniqueRicketts
Aug 04 2017 13:44
@Blauelf how far are you on fcc?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 13:44
so array[array.length], or array[1] in this case has not been defined, ergo, array[1] is undefined.
EpicTriffid
@EpicTriffid
Aug 04 2017 13:45
@Blauelf @kumquatfelafel It makes sense! Thanks
CamperBot
@camperbot
Aug 04 2017 13:45
epictriffid sends brownie points to @blauelf and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 568 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 4555 | @blauelf |http://www.freecodecamp.com/blauelf
kumquatfelafel
@kumquatfelafel
Aug 04 2017 13:45
And as @Blauelf points out, array[array.length] will, more generally, be undefined.
Blauelf
@Blauelf
Aug 04 2017 13:45
@RoniqueRicketts Haven't done the front end projects yet. I somewhat like the JS part more than the dirty HTML/CSS.
EpicTriffid
@EpicTriffid
Aug 04 2017 13:45
@kumquatfelafel So < instead of <= means i'll never reach the limit for the code to freak out about?
Blauelf
@Blauelf
Aug 04 2017 13:47
@EpicTriffid < means you loop only the valid indices (for collection.length, the loop won't enter the body but exit), and at those valid indices you'll probably find objects, not undefined
EpicTriffid
@EpicTriffid
Aug 04 2017 13:48
@Blauelf And would you be able to explain how Object.keys works? Im looking at it but it makes no sense
Blauelf
@Blauelf
Aug 04 2017 13:48
Object.keys returns an array containing the names of all the enumerable properties of an object.
EpicTriffid
@EpicTriffid
Aug 04 2017 13:48
@Blauelf Sorry, i feel like i;m just throwing stupid questions at you
Blauelf
@Blauelf
Aug 04 2017 13:49
You can then (in an inner loop) iterate over that array.
Thayyeb salim
@Thayyebsalim
Aug 04 2017 13:49
Guys I have a doubt
Is it better to write JS in the script section or to link it
Stephen James
@sjames1958gm
Aug 04 2017 13:50
@Thayyebsalim Unless the js is really small, link it.
EpicTriffid
@EpicTriffid
Aug 04 2017 13:50
@Blauelf So it kind of disseminates all the properties within the object like you would extract all the elements out of an array?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 13:51
@EpicTriffid Generally speaking, when the intent is to iterate through the entire array, you want to stop at the point such that the highest referenced element index is array.length - 1. Whether that is i < array.length or some other value may depend on what you're doing.
Thayyeb salim
@Thayyebsalim
Aug 04 2017 13:52
thank you @sjames1958gm
CamperBot
@camperbot
Aug 04 2017 13:52
thayyebsalim sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8243 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Blauelf
@Blauelf
Aug 04 2017 13:52
@EpicTriffid Object.keys returns an array of property names, not their corresponding values.
EpicTriffid
@EpicTriffid
Aug 04 2017 13:52
@kumquatfelafel Perfect! Makes sense!
@Blauelf So an object like {name: Phil, age: 34, location: UK} would return ["name", "age", "location"] with Object.keys?
Blauelf
@Blauelf
Aug 04 2017 13:54
Yes, probably. The order of the properties might differ.
Kelechi Chinaka
@ke1echi
Aug 04 2017 13:56
function initials(str){
  return str.split(' ').map((element) => {
    if (element === str[str.length - 1]) {
      return element[0].toUpperCase() + element.slice(1)
    } 
    if (element !== str[str.length - 1]) {
      return element[0].toUpperCase()
    }    
  });
}
expects: 'B.H.Obama' got: B.H.O
what am i not seeing
EpicTriffid
@EpicTriffid
Aug 04 2017 13:58
@kumquatfelafel @Blauelf When would i use forEach, and when would i use a for loop?
Diego Mayer
@Chrono79
Aug 04 2017 13:59
@kelechy why would be element equal to str[str.length - 1] ?
str is still a string, str.split(' ') is an array
kumquatfelafel
@kumquatfelafel
Aug 04 2017 13:59
@kelechy str[str.length - 1] is a single character that you're comparing to element which is a word
Kelechi Chinaka
@ke1echi
Aug 04 2017 14:00
str[str.length - 1] i thought is the last word in the string array
how do i reference the last word
Simon Cordova
@gbsimon87
Aug 04 2017 14:01
What's up @Chrono79
Diego Mayer
@Chrono79
Aug 04 2017 14:01
:wave:
fighting several fronts at a time
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:01
@kelechy sec, let me reread your code to make sure reading it right
Diego Mayer
@Chrono79
Aug 04 2017 14:01
@kelechy create a var arr and store the array there
Kelechi Chinaka
@ke1echi
Aug 04 2017 14:02
arr = ["Barack", "hussain", "obama"]
arr[arr.length - 1]
"obama"
i dont get it @Chrono79
Diego Mayer
@Chrono79
Aug 04 2017 14:02
:+1:
why not?
Blauelf
@Blauelf
Aug 04 2017 14:03

@EpicTriffid You can use forEach if you have a function you want to call for each element of an array. Makes sense only for the side-effects of this function.
Another higher-order function, map, would instead take all the return values and construct a new array of the same size.
Then there's filter, which creates a new array from a selection of the array's elements.

A for loop could replace them all, it's mostly about readability. For example in the whatIsInAName, I used filter for the outer loop over collection and every for the inner loop over the result of Object.keys(source) stored in a variable.

Kelechi Chinaka
@ke1echi
Aug 04 2017 14:03
u mean aftyer the split? @Chrono79
Diego Mayer
@Chrono79
Aug 04 2017 14:03
function initials(str){
  var arr = str.split(' ');
  return arr.map((element) => {
    if (element === arr[arr.length - 1]) {
      return element[0].toUpperCase() + element.slice(1)
    } else {
      return element[0].toUpperCase()
    }    
  }).join('.');
}
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:04
as @Chrono79 says. str[str.length - 1] is the final character in the string, i.e. a. Remember, str.split() does not actually modify the value of original variable str, it returns a new array. So when you reference str later in your map function, you're actually referencing the old string
Kelechi Chinaka
@ke1echi
Aug 04 2017 14:05
ohh!! i feel daft :smile: @Chrono79 @kumquatfelafel
EpicTriffid
@EpicTriffid
Aug 04 2017 14:06
@Blauelf I just copied that into a notepad to remember. Perfect explanation haha
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:08
@Chrono79 one more note in regards to this... what if name is, e.g., "Barack Obama Obama"? ;)
Kelechi Chinaka
@ke1echi
Aug 04 2017 14:08
thanks for that clarification @kumquatfelafel @Chrono79
CamperBot
@camperbot
Aug 04 2017 14:08
kelechy sends brownie points to @kumquatfelafel and @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 569 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 4506 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Aug 04 2017 14:09
@kumquatfelafel he should use the index then
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:09
@Chrono79 I'm thinking that's safer yeah
Diego Mayer
@Chrono79
Aug 04 2017 14:09
function initials(str){
  var arr = str.split(' ');
  return arr.map((element, i) => {
    if (i === arr.length - 1) {
      return element[0].toUpperCase() + element.slice(1)
    } else {
      return element[0].toUpperCase()
    }    
  }).join('.');
}
Kelechi Chinaka
@ke1echi
Aug 04 2017 14:09
lastIndexOf should do it
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:09
(assuming intent is to initialize all but last element, anyway)
Ronique Ricketts
@RoniqueRicketts
Aug 04 2017 14:10
@Blauelf YEah JS is nice. I like the language. I really want to master the little that I have been introduced.
Diego Mayer
@Chrono79
Aug 04 2017 14:11
@kelechy lastIndexOf performs worse than comparing i against the length I guess
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:13
I'm also not entirely sure how you would implement this without doing something weird :point_up:
Diego Mayer
@Chrono79
Aug 04 2017 14:14
@kumquatfelafel there are more edge cases like two surnames, but I don't know how one could address that without separating the input in two fields
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:15
Do you mean like hyphenated?
Diego Mayer
@Chrono79
Aug 04 2017 14:17
not hyphenated, like father's surname and mother's surname
Kelechi Chinaka
@ke1echi
Aug 04 2017 14:17
hmm thats true @Chrono79
Diego Mayer
@Chrono79
Aug 04 2017 14:18
some countries have that way of naming people
or single and married surname (this one I guess could be hyphenated in some countries)
Kelechi Chinaka
@ke1echi
Aug 04 2017 14:25
function filter(array) {
  var  newArray = [];
  for (var i = 0; i <= array.length; i++) {
    if (array[i] > 3) {
      newArray.push(array[i]);
    }
  }
  return newArray;
}
this func works but returns undefined at CW could it be a kata issue? @kumquatfelafel @Chrono79
Darth Skywalker
@AdiSkywalker
Aug 04 2017 14:29
@kelechy post the kata link here please
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:29
@Chrono79 map with a default function that assumes last name is surname, but allow to pass in different function (to deal with different... "naming paradigm"???) if need be? :laughing:
Keon Samuel
@keonsam
Aug 04 2017 14:35
i < array.length
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:35
@kelechy look at the sample test. Is it passing an array as argument in parentheses?
Diego Mayer
@Chrono79
Aug 04 2017 14:36
@kelechy it's not a kata issue
[1,2,3,4].filter((num)=>{ return num > 3}) note how the method is called, you have to use prototype
Keon Samuel
@keonsam
Aug 04 2017 14:37
@Chrono79 :+1:
Kelechi Chinaka
@ke1echi
Aug 04 2017 14:40
ohh
my skills on prototype are not high
EpicTriffid
@EpicTriffid
Aug 04 2017 14:42
So this is working for the first example, but not with the second. Any idea why?

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

  var temp = "";
  for (var i = 0; i < collection.length; i++) {
    if (collection[i].hasOwnProperty(Object.keys(source))) {
      temp = collection[i];
    }
  }
  arr.push(temp);

  return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];

  var temp = "";
  for (var i = 0; i < collection.length; i++) {
    if (collection[i].hasOwnProperty(Object.keys(source))) {
      temp = collection[i];
    }
  }
  arr.push(temp);

  return arr;
}

whatIsInAName([{ "a": 1 }, { "a": 1 }, { "a": 1, "b": 2 }], { "a": 1 })
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:43
@kelechy e.g.
String.prototype.doSomething = function() {
  return 5;
}
console.log("Hello world".doSomething()) //outputs 5
Kelechi Chinaka
@ke1echi
Aug 04 2017 14:43
do i need to use same logic i used for the function then wrap it inside a prototype
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:46
@kelechy If you're convinced that the parameter is an array, then yes (it's not though).
@kelechy Your function is supposed to take as an argument a function that checks if some condition is true.
But the bones are mostly good, other than that.
Kelechi Chinaka
@ke1echi
Aug 04 2017 14:49
ok its beginining to make sense, buh the arg seems to be an integer
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:50
the argument, in full, is (num)=>{ return num > 3}
Stephen James
@sjames1958gm
Aug 04 2017 14:52
@EpicTriffid It shouldn't work for either. Object.keys(source) this returns an array which will never be a property
Kelechi Chinaka
@ke1echi
Aug 04 2017 14:53
so the function takes an arg @kumquatfelafel
kumquatfelafel
@kumquatfelafel
Aug 04 2017 14:54
The above is es6 version of...
function (num) {
  return num > 3;
}
you are, effectively, passing this :point_up: into your function.
Kelechi Chinaka
@ke1echi
Aug 04 2017 14:59
ok @kumquatfelafel
ashish singh
@ashish1729
Aug 04 2017 14:59
@EpicTriffid ..your function is very wrong.. it will always return the last element in collection .. see your push is outside the loop... hasOwnProperty .. doesnt take an array
Christopher McCormack
@cmccormack
Aug 04 2017 15:02
it might take an array, I was just testing it:
> var source = Object.keys({last: "Capulet"})
> source
[ 'last' ]
> var coll = {first: "romeo", last: "capulet"}
> coll.hasOwnProperty(source)
true
> coll.hasOwnProperty(['first'])
true
> coll.hasOwnProperty(['second'])
false
> coll.hasOwnProperty(['first', 'last'])
false
Kelechi Chinaka
@ke1echi
Aug 04 2017 15:03
Array.prototype.filter = function (num) {
  var box = []
  for (var i = 0; i <= this.length; i++) {
    if (this[i] > 3) {
      box.push(this[i])
    }
  }
  return box
}
fails random test @kumquatfelafel
Christopher McCormack
@cmccormack
Aug 04 2017 15:04
Perhaps single entry array with a string is coerced into a string
kumquatfelafel
@kumquatfelafel
Aug 04 2017 15:04
@kelechy Because it's wrong. :p
You're passing a function reference, not num.
example coming in sec.
Kelechi Chinaka
@ke1echi
Aug 04 2017 15:06
i feel terrible :worried: @kumquatfelafel
kumquatfelafel
@kumquatfelafel
Aug 04 2017 15:17

you can assign a function to a variable.

var blah = Array.prototype.pop;
var array = [1,2,3,4,5];
array.blah(); //[1,2,3,4] remains.
array.blah(); //[1,2,3] remains
array.pop(); //[1,2] remains.

Going back to my earlier example (modified slightly), can also pass function reference into another function (and invoke it from there like so....

String.prototype.doSomething = function(num) {
  return num + 23;
}
var someFunction = function(func, num) {
  if (func(num) === 46) 
    console.log("Hooray! 46!");
  else
    console.log(func(num));
}

someFunction(String.prototype.doSomething, 23); // "Hooray! 46!"
someFunction(String.prototype.doSomething, 19); // 42
//can also pass in functions anonymously
someFunction(num => 2*num, 23); //"Hooray! 46!"
@kelechy
Darth Skywalker
@AdiSkywalker
Aug 04 2017 15:21

@kumquatfelafel

String.prototype.doSomething = function(num) {
  return num + 23;
}

If you want to work on num why bother creating a function on String.prototype ?

That's like "asd".doSomething(5) // 28
kumquatfelafel
@kumquatfelafel
Aug 04 2017 15:22
@AdiSkywalker Because I was too lazy to write a new function.
@AdiSkywalker It's silly, of course, but original example was just to show the "skeleton" of creating function using prototype.
Darth Skywalker
@AdiSkywalker
Aug 04 2017 15:23
@kumquatfelafel :+1:
kumquatfelafel
@kumquatfelafel
Aug 04 2017 15:28
@kelechy though yeah, doesn't necessarily have to be a prototype function either. Can also just be something stored in a regular old var, e.g.
var aFunction = function(num) {
  return num? 46: 0;
}
someFunction(aFunction, 5); // "Hooray! 46!"
someFunction(aFunction, 0); // 0
someFunction(aFunction, true); // "Hooray! 46!"
Kelechi Chinaka
@ke1echi
Aug 04 2017 15:30
do i use this to ref the array..u know i have to use num to tranverse the array
kumquatfelafel
@kumquatfelafel
Aug 04 2017 15:31
@kelechy You can use this to reference the array (in the context of the prototype function), yes.
this, in the given context, basically refers to the object that the function is being called on.
Stephen James
@sjames1958gm
Aug 04 2017 15:49
@Datikzz Seems reasonable approach
teevik
@teevik
Aug 04 2017 15:54
@Datikzz Yeah, you would need some sort of array which contains the information for drawing each ball
You could use OOP
Janice He
@Janicekwing
Aug 04 2017 16:02
Hi all, can someone be the extra eyes for my code?
Christopher McCormack
@cmccormack
Aug 04 2017 16:03
Sure someone can
Janice He
@Janicekwing
Aug 04 2017 16:04
It's Java though... the task is to capitalize the first letter of each word in a phrase
public class JadenCase {

    public String toJadenCase(String phrase) {

   StringBuilder newPhrase= new StringBuilder(phrase.length());
    if (phrase.length() < 1 || phrase == null) {return null;}
    newPhrase.append(Character.toUpperCase(phrase.charAt(0)));

    for (int i=1; i<phrase.length(); i++) {
      if (phrase.charAt(i-1)=' ') {
          newPhrase.append(Character.toUpperCase(phrase.charAt(i)));
      } else {
          newPhrase.append(phrase.charAt(i));
      }

        return newPhrase.toString();
    }

}
}
Jason Luboff
@JLuboff
Aug 04 2017 16:04
This is a javascript room...you're going to be hard pressed to find help with java..
kumquatfelafel
@kumquatfelafel
Aug 04 2017 16:04
java is fine. need a moment to look at/remember though. :p
Jason Luboff
@JLuboff
Aug 04 2017 16:05
@cmccormack We're going :fishing_pole_and_fish:
kumquatfelafel
@kumquatfelafel
Aug 04 2017 16:05
Also I'm very sleep deprived so I can't 100% guarantee I'll give you correct answer. @Janicekwing
Janice He
@Janicekwing
Aug 04 2017 16:05
If the phrase is "How can mirrors be real if our eyes aren't real"... then it should return "How Can Mirrors Be Real If Our Eyes Aren't Real"
@kumquatfelafel no worries, appreciate anything at this point
I am basically starting a new string and taking each character from the original phrase, unless it has a space in front of it, I capitalize it... before the for loop, I upper case the first letter of the phrase since there's no space in front of it
Christopher McCormack
@cmccormack
Aug 04 2017 16:09
@Janicekwing what issues are you running into first?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 16:09
@Janicekwing opening IDE so can run/test. In meantime, any particular cases that should work that aren't? (and what is the incorrect result)
Christopher McCormack
@cmccormack
Aug 04 2017 16:11
@Janicekwing you're returning in your for loop so it will only check second character
kumquatfelafel
@kumquatfelafel
Aug 04 2017 16:12
:point_up: yeah. that will cause problems
Janice He
@Janicekwing
Aug 04 2017 16:13
oh
honestly, not really sure what the problem is, because error msg I get is:
error: unexpected type
      if (phrase.charAt(i-1)=' ') {
                       ^
  required: variable
  found:    value
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

*
Darth Skywalker
@AdiSkywalker
Aug 04 2017 16:14
@Janicekwing full code please
Janice He
@Janicekwing
Aug 04 2017 16:15
I moved the return statement down by a curly bracket but I still get the same error msg
@AdiSkywalker you can see it, if you scroll up a little!
kumquatfelafel
@kumquatfelafel
Aug 04 2017 16:16
@Janicekwing =?
@Janicekwing what does = mean? ;)
Janice He
@Janicekwing
Aug 04 2017 16:17
oohh
Darth Skywalker
@AdiSkywalker
Aug 04 2017 16:17
in java you gotta use .equals
Janice He
@Janicekwing
Aug 04 2017 16:17
@kumquatfelafel omg I love youu, that solved it!!
Darth Skywalker
@AdiSkywalker
Aug 04 2017 16:17
instead of ==
phrase.charAt(i-1).equals(' ')
kumquatfelafel
@kumquatfelafel
Aug 04 2017 16:18
== is fine for a single character actually.
if it were a string though, yeah, you would want .equals().
@AdiSkywalker any who, charAt returns the primitive char so .equals actually wouldn't work... unless there was autoboxing in this scenario... I don't think there was??? but don't remember.
Seth
@sethdcd
Aug 04 2017 16:22

hi all how would i create a statement to add an additional [] to my variable array?

for example: arr[0] would then become something like arr[0][0]

i tried doing something like arr[0] + [] but that didnt work

Jason Luboff
@JLuboff
Aug 04 2017 16:22
@sethdcd use push/unshift
Darth Skywalker
@AdiSkywalker
Aug 04 2017 16:22
@kumquatfelafel :+1:
Seth
@sethdcd
Aug 04 2017 16:23
@JLuboff push can add on another matrix?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 16:23
@AdiSkywalker It's kinda terrifying how foreign java looks these days. :p
Darth Skywalker
@AdiSkywalker
Aug 04 2017 16:23
haha!
Janice He
@Janicekwing
Aug 04 2017 16:24
@kumquatfelafel thanks :)!!
CamperBot
@camperbot
Aug 04 2017 16:24
janicekwing sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 570 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Darth Skywalker
@AdiSkywalker
Aug 04 2017 16:24
thats kinda true
Jason Luboff
@JLuboff
Aug 04 2017 16:24
@sethdcd
let arr = [];
arr.push([1]);
console.log(arr); // [[1]]
Seth
@sethdcd
Aug 04 2017 16:25
@JLuboff hmm ok, well i'm not trying to add values into an array, i'm actually trying to flatten. i need something that will add another matrix onto my variable array if Array.isArray returns false so it can go a layer deeper
Abhishek Tiwari
@fillopfy
Aug 04 2017 16:33
@sethdcd use recursion method to flatten by going deeper into the array
Seth
@sethdcd
Aug 04 2017 16:34
@fillopfy right that is what im trying to do, but i need to have it add on a matrix to go deeper
@fillopfy right? that is really what my question is, how would i go about adding that on
Abhishek Tiwari
@fillopfy
Aug 04 2017 16:35
@sethdcd you can use reduce method that will keep on concating two passed value if second one is not array, if second element is array(Array.isArray), then call the function again
Seth
@sethdcd
Aug 04 2017 16:36
@fillopfy oh i see ok
@fillopfy thanks
CamperBot
@camperbot
Aug 04 2017 16:36
sethdcd sends brownie points to @fillopfy :sparkles: :thumbsup: :sparkles:
:cookie: 297 | @fillopfy |http://www.freecodecamp.com/fillopfy
kumquatfelafel
@kumquatfelafel
Aug 04 2017 16:54
...
So I suppose this kinda goes against the spirit of FreeCodeCamp? :p
function orbitalPeriod(arr) {
  //var GM = 398600.4418;
  //var earthRadius = 6367.4447;
  //return arr;
  return true;
}

this.tests = ["assert.deepEqual(orbitalPeriod([{name : \"sputnik\", avgAlt : 35873.5553}]), true, 'message: <code>orbitalPeriod([{name : \"sputnik\", avgAlt : 35873.5553}])</code> should return <code>true</code>.');"];
:laughing:
Janice He
@Janicekwing
Aug 04 2017 16:56
@kumquatfelafel can I use you again :)?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 16:57
@Janicekwing possibly
Janice He
@Janicekwing
Aug 04 2017 16:57
in the same code, I am supposed to return null if phrase is null or an empty string
this is what I tried, it works for an empty string but not if phrase is null
public class JadenCase {

    public String toJadenCase(String phrase) {

        StringBuilder newPhrase= new StringBuilder(phrase.length());
    if (phrase.length() >= 1) {
    newPhrase.append(Character.toUpperCase(phrase.charAt(0)));

    for (int i=1; i<phrase.length(); i++) {
      if (phrase.charAt(i-1)==' ') {
          newPhrase.append(Character.toUpperCase(phrase.charAt(i)));
      } else {
          newPhrase.append(phrase.charAt(i));
      }


    }
        return newPhrase.toString();
} return null;
} 
}
I inserted the first if statement and the last return statement
kumquatfelafel
@kumquatfelafel
Aug 04 2017 16:59
@Janicekwing are you getting null pointer exception, essentially is what you're saying?
Janice He
@Janicekwing
Aug 04 2017 17:00
yes
Christopher McCormack
@cmccormack
Aug 04 2017 17:01
@a7n007 without looking too closely, I would recommend you move your collectionCopy within your updateRecords function
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:01

@Janicekwing So you were actually very close before with
if (phrase.length() < 1 || phrase == null) {return null;}

The problem with this however, is that going left to right, it will check the length before checking if phrase is null (you can't call .length() on null)

@Janicekwing You want to check if phrase is null first, and since you have ||, that will prevent it from checking the second condition (since first one already true), where the nullpointerexception would be thrown.
Christopher McCormack
@cmccormack
Aug 04 2017 17:03
@a7n007 also if value is falsey, if(collectionCopy[id][prop]) condition will be false. I don't fully remember the exercise but make sure that's what you want
a7n007
@a7n007
Aug 04 2017 17:04
@cmccormack so what should i do BTW its working for all test cases when individually tested
Janice He
@Janicekwing
Aug 04 2017 17:05
@kumquatfelafel I see... but shouldnt my updated code override that?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:05
@Janicekwing basically... try reversing the order you check your conditions.
Janice He
@Janicekwing
Aug 04 2017 17:05
I tried to make it simpler by saying if (phrase.length >= 1) { ...} otherwise return null;
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:05
@Janicekwing Is your updated code what you just posted above?
Christopher McCormack
@cmccormack
Aug 04 2017 17:05
@a7n007 ah then you probably just need to move your var collectionCopy = JSON.parse(JSON.stringify(collection)); inside your function
Janice He
@Janicekwing
Aug 04 2017 17:06
and when null would be false in that if statement
and yes, the code I just uploaded is updated!
Nadia
@nadiaschutz
Aug 04 2017 17:06
hi guys
Christopher McCormack
@cmccormack
Aug 04 2017 17:07
hello
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:08
@Janicekwing the problem with if (phrase.length() >= 1) is...
String blah = null;
blah.length(); //this throws a nullpointerexception since you're calling a method on null.
a7n007
@a7n007
Aug 04 2017 17:08
@cmccormack still not working can you please try it in your editor and tell me if it is working.
Janice He
@Janicekwing
Aug 04 2017 17:08
hmm I see
Christopher McCormack
@cmccormack
Aug 04 2017 17:09
@a7n007 why don't you copy it into a codepen along with the examples and we can look at that
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:10
@Janicekwing This doesn't break code on other hand...
String blah = "";
blah.length();
Jason Luboff
@JLuboff
Aug 04 2017 17:10
@cmccormack Sent out my phishing email. So far no one has fallen for it (maybe...they're learning?!)
Nadia
@nadiaschutz
Aug 04 2017 17:10
//how to reset  a global arr variable? can't figure it out. cuz the arr comes with new variables each time and the length may change
function generate_options(options){
options=options;

//some other stuff
}
Janice He
@Janicekwing
Aug 04 2017 17:11

so I tried..

if (phrase == null  || phrase.length() < 1) {return null;}

but I still receive a null pointer exception, do you know if I am allowed to return null?

kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:11
@Janicekwing So this is why you have to check first whether phrase is null, before calling the length method.
Christopher McCormack
@cmccormack
Aug 04 2017 17:11
@JLuboff Maybe - it was a bank thing right?
@JLuboff BofA?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:11
@Janicekwing hm... sec
Christopher McCormack
@cmccormack
Aug 04 2017 17:12
@nadiaschutz can you provide more detail? Your code is missing any global variable declarations or arrays
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:12

do you know if I am allowed to return null?

(you are allowed to return null, though if you call a method on that return, it will result in an NPE as well. That being said, let me try running your code and see what happens)

a7n007
@a7n007
Aug 04 2017 17:13
@cmccormack how to run js in codepen
Jason Luboff
@JLuboff
Aug 04 2017 17:13
@cmccormack Nah, did it as an Office 365 Password reset request
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:13
@Janicekwing actually, just... making sure, what's your code look like now?
Janice He
@Janicekwing
Aug 04 2017 17:13
it's weird that it returns null if it's an empty string but not, when phrase itself is null
Christopher McCormack
@cmccormack
Aug 04 2017 17:14
@a7n007 paste your code into the JS section and make sure you save. Then use the browser's developer console along with console.log statements to see the results
a7n007
@a7n007
Aug 04 2017 17:14
thats what i did
Christopher McCormack
@cmccormack
Aug 04 2017 17:14
@JLuboff ah that's right, and they all have O365 right?
Janice He
@Janicekwing
Aug 04 2017 17:14
public class JadenCase {

    public String toJadenCase(String phrase) {

        StringBuilder newPhrase= new StringBuilder(phrase.length());
    if (phrase == null || phrase.length() < 1) {return null;} 
    newPhrase.append(Character.toUpperCase(phrase.charAt(0)));

    for (int i=1; i<phrase.length(); i++) {
      if (phrase.charAt(i-1)==' ') {
          newPhrase.append(Character.toUpperCase(phrase.charAt(i)));
      } else {
          newPhrase.append(phrase.charAt(i));
      }


    }
        return newPhrase.toString();

} 
}
Christopher McCormack
@cmccormack
Aug 04 2017 17:15
@a7n007 well then if you did you could link the pen and share it with us
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:15
@Janicekwing
new StringBuilder( :point_right: phrase.length() :point_left: );
Jason Luboff
@JLuboff
Aug 04 2017 17:15
@cmccormack Yup! I'm actually quite happy so far lol. My email doesn't look too shabby either but has obivious red flags
Christopher McCormack
@cmccormack
Aug 04 2017 17:16
@a7n007 so the main suggestion I provided you did not implement - move var collectionCopy = JSON.parse(JSON.stringify(collection)); inside your function
@JLuboff who is it sent from?
Jason Luboff
@JLuboff
Aug 04 2017 17:16
@cmccormack ITDepartment@ourdomain.com which we've never used before (I just created it this morning)
blob
Christopher McCormack
@cmccormack
Aug 04 2017 17:16
hah nice
Janice He
@Janicekwing
Aug 04 2017 17:17
@kumquatfelafel sorry but I dont see the difference lol?
@kumquatfelafel OOOHH
Nadia
@nadiaschutz
Aug 04 2017 17:18

    function generate_options(options) {
      /*  options.preventDefault();*/

        options=options;
       /*if (options.length>3){
            options.length=3;
            }else{*/

            generate_message('Did you mean:', 'bot');

        var str = "";
        var i;
        for (i = 0; i < options.length; i++) {
            INDEX++;

            str = "<div id='cm-msg-" + INDEX + "' class=\"options\">";
            str += "<button class=\"options-btn\" >";
            str += options[i];
            str += "          <\/button>";
            str += "        <\/div>";

             //send the string to chat-log window
            $(".chat-logs").append(str);
            //message animation to show up on the screen with 500mls delay
            $("#cm-msg-" + INDEX).hide().fadeIn(500);
            }

        //choose button option
            $(".options-btn").click(function(e){
                e.preventDefault();
                var btnVal=$(this).html();
                console.log(btnVal);
                //show chosen option in the chat logs
                $(".chat-logs").append(function(){
                    generate_message(btnVal, 'self');
                    callbot(btnVal);
                });
                });
        console.log(options);
           /* }*/


        }
@cmccormack
a7n007
@a7n007
Aug 04 2017 17:18
@cmccormack i tried it but it didnot make a difference
Nadia
@nadiaschutz
Aug 04 2017 17:19
@cmccormack so to your question...no ,,,it's not missing any variables
Janice He
@Janicekwing
Aug 04 2017 17:20
@kumquatfelafel thanks, that makes sense! although idk about you but from my end, I'm still getting nullpointerexception lol.. maybe I just need to look at it a little longer
CamperBot
@camperbot
Aug 04 2017 17:20
janicekwing sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:warning: janicekwing already gave kumquatfelafel points
Nadia
@nadiaschutz
Aug 04 2017 17:21
@cmccormack i just need to reset options each time....otherwise i get loooong arr of options
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:22
@Janicekwing you dealt with the new StringBuilder( :point_right: phrase.length() :point_left: ); ?
Janice He
@Janicekwing
Aug 04 2017 17:22
@kumquatfelafel I switched those two lines:
    if (phrase == null || phrase.length() < 1) {return null;} 
    StringBuilder newPhrase= new StringBuilder(phrase.length());
is something wrong with phrase.length() ?
@kumquatfelafel I just refreshed, it works :)
Jiri Laza
@N4thyra
Aug 04 2017 17:25
@Janicekwing it should be phrase.length
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:26
@N4thyra java
a7n007
@a7n007
Aug 04 2017 17:26
@cmccormack it is a question with a bug.
Jiri Laza
@N4thyra
Aug 04 2017 17:26
@kumquatfelafel I see. My bad. I should have thought of that
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:27
@N4thyra np. Not very usual to see java here. :laughing:
Janice He
@Janicekwing
Aug 04 2017 17:28
@kumquatfelafel no phrase.length() was fine actually! switching those 2 lines solved the issue :) thanks againn
CamperBot
@camperbot
Aug 04 2017 17:28
janicekwing sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 571 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Christopher McCormack
@cmccormack
Aug 04 2017 17:29
@nadiaschutz try just changing your parameter to a different name so you aren't using the same variable name
Kelechi Chinaka
@ke1echi
Aug 04 2017 17:32
function facRecursion(value){
  if(value < 0) {
    return 0;
  }
  if(value === 0) {
    return 1;
  }
  return value * (facRecursion(value - 1));
}
i did a recursive fun passes all test except one
Your function did not recurse enough times - Expected: 3, instead got: 2
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:32
@Janicekwing from an efficiency standpoint, it really makes more sense to switch those lines as well. If you think about it, you don't want to create StringBuilder unless you're going to actually "build" a string. Generally speaking, you want to put those early "don't bother performing this task" returns at very top.
Kelechi Chinaka
@ke1echi
Aug 04 2017 17:33
it wants to recurse 3 times, but it recurses 3times on python tutor :smile:
Christopher McCormack
@cmccormack
Aug 04 2017 17:36
@a7n007 your delete doesn't work because you're deleting from collectionCopy but never doing anything else with collectionCopy
kumquatfelafel
@kumquatfelafel
Aug 04 2017 17:37
Off for now.
Christopher McCormack
@cmccormack
Aug 04 2017 17:37
@a7n007 ignore what I said about collectionCopy moving into your function, I didn't realize the exercise explicitly defined that and stated not to modify it
Nadia
@nadiaschutz
Aug 04 2017 17:39
@cmccormack that's not going to work.
Christopher McCormack
@cmccormack
Aug 04 2017 17:45
@nadiaschutz oh? Why do you say that?
Stephen James
@sjames1958gm
Aug 04 2017 17:45
@kelechy Which kata?
Nadia
@nadiaschutz
Aug 04 2017 17:49
@cmccormack cuz var options comes with an array of variables already...and it just keep adding...changing the name , asigning options to var b not working.....i tried pushing options into a new arr....and it shows arr=undefined...
Christopher McCormack
@cmccormack
Aug 04 2017 17:50
@nadiaschutz I'm suggesting you change your parameter name to something like function generate_options(newOptions) {
Nadia
@nadiaschutz
Aug 04 2017 17:51
@cmccormack i got you...that's not working this way i mean it doesn't really matter what name you put there...the arr is still growing..
Christopher McCormack
@cmccormack
Aug 04 2017 17:54
@nadiaschutz do you have a codepen or something we can refer to? I'm not sure how your options keep growing if you aren't appending items to it in the code you provided
Stephen James
@sjames1958gm
Aug 04 2017 17:59

@kelechy try

if (value <= 1) return 1;

The message might be wrong it may be recursing too many times.

CallMeOrange
@EgnaroDev
Aug 04 2017 17:59
@sjames1958gm Do you know which kata is this?
Stephen James
@sjames1958gm
Aug 04 2017 17:59
@EgnaroDev I do not, I asked
CallMeOrange
@EgnaroDev
Aug 04 2017 17:59
oh ok
@sjames1958gm I'm really stuck with Sorted Union, was wondering if you can take a look
function uniteUnique(arr) {
var array = [];
 for (var i = 0; i < arguments.length; i++){
   for (var j = 0; j < arguments[i].length; j++){
   array.push(arguments[i][j]);
   }
 }
 return array.filter(function(e){
   ...
 });
}

uniteUnique([1, 3, 2], [2, 1]); // should return [1, 3, 2].
Not sure if .filter() is all I have to do
Stephen James
@sjames1958gm
Aug 04 2017 18:02
@EgnaroDev .filter should be enough - if you know what values you want to keep
CallMeOrange
@EgnaroDev
Aug 04 2017 18:03
Oh ok, I have no idea what I am supposed to compare or how to remove the same value as another in an array
Christopher McCormack
@cmccormack
Aug 04 2017 18:03
might be better to use a reduce method instead, then you can push unique values to the accumulator and test against that
CallMeOrange
@EgnaroDev
Aug 04 2017 18:04
What do you mean by accumulator?
like pushing values into a variable?
Christopher McCormack
@cmccormack
Aug 04 2017 18:05
reduce has an accumulator as the first parameter, something that stores a value of some sort. The second argument to the reduce function can be used to specify the initial accumulator
if no initial accumulator it uses the first item in the array
Stephen James
@sjames1958gm
Aug 04 2017 18:06
@EgnaroDev Maybe indexOf and compare to current index.
CallMeOrange
@EgnaroDev
Aug 04 2017 18:06
oh .indexOf() might be good idea
Stephen James
@sjames1958gm
Aug 04 2017 18:06
@EgnaroDev recall that .filter gets three parameters: (element, index, array)
CallMeOrange
@EgnaroDev
Aug 04 2017 18:07
I know two of these parameters, I'm going to research .filter() again what array does
Stephen James
@sjames1958gm
Aug 04 2017 18:08
array is just the array - useful if you are chaining and don't have a variable with the array
CallMeOrange
@EgnaroDev
Aug 04 2017 18:09
Hm..
Thomas Faller
@thomasfaller
Aug 04 2017 18:09
Hey guys,
I’m dong the Spinal Tap Case where ThisIsIt should return this-is-it but I’m failing to handling the spaces… I’m only able to insert - before the Caps letters but not replacing the spaces… I looked up regular expressions tutorials and I don’t know how to make it ‘exclusive’ so that it replaces spaces or _
https://codepen.io/thomasfaller/pen/RZoMoN
CallMeOrange
@EgnaroDev
Aug 04 2017 18:10
I'm going to try .indexOf() right now, @sjames1958gm thanks
CamperBot
@camperbot
Aug 04 2017 18:10
egnarodev sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8244 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 04 2017 18:10
@EgnaroDev :+1: you can do it :)
@thomasfaller /\s*([A-Z])/g
kumquatfelafel
@kumquatfelafel
Aug 04 2017 18:12
@EgnaroDev And after you've done it, I'll show you the most advanced possible solution conceivable by rodentkind! :o
CallMeOrange
@EgnaroDev
Aug 04 2017 18:12
lol sure
Christopher McCormack
@cmccormack
Aug 04 2017 18:15
@kumquatfelafel I want to compare yours to mine so let's do a countdown when it's time :D
Thomas Faller
@thomasfaller
Aug 04 2017 18:15
@sjames1958gm * damn!!!!
Thanks!
CallMeOrange
@EgnaroDev
Aug 04 2017 18:15
But this is going to take a while..
Thomas Faller
@thomasfaller
Aug 04 2017 18:16
f…ing regular expressions!!!
kumquatfelafel
@kumquatfelafel
Aug 04 2017 18:16
@cmccormack Oh, definitely! But I'm pretty sure that mine can't be beat!!! Both in terms of it's elegant simplicity and it's robustness.
Christopher McCormack
@cmccormack
Aug 04 2017 18:17
I hope to learn something from it!
kumquatfelafel
@kumquatfelafel
Aug 04 2017 18:19
I assure you, I shall almost certainly learn more from yours :p
Christopher McCormack
@cmccormack
Aug 04 2017 18:23
what not to do? haha
kumquatfelafel
@kumquatfelafel
Aug 04 2017 18:29
Perhaps we should have waited before talking up our solutions. Now, the fanfare will be reduced when the time comes.
Christopher McCormack
@cmccormack
Aug 04 2017 18:30
hah agreed
kumquatfelafel
@kumquatfelafel
Aug 04 2017 18:31
If only I possessed more of a filter.
Jason Luboff
@JLuboff
Aug 04 2017 18:35
You guys have me all hyped up
Christopher McCormack
@cmccormack
Aug 04 2017 18:36
haha @kumquatfelafel so clever
@JLuboff you should participate!
Jason Luboff
@JLuboff
Aug 04 2017 18:39
In what? lol
EpicTriffid
@EpicTriffid
Aug 04 2017 18:39
Yello all. So, this code, according to people is rrrreeeaaallly wrong. It seems that Object.keys(source) is the problem, yet I was under the impression that I'm asking it to cycle through the code, and if it finds the same properties as in source, push that the array? Where am I going wrong?

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

  var temp = "";
  for (var i = 0; i < collection.length; i++) {
    if (collection[i].hasOwnProperty(Object.keys(source))) {
      temp = collection[i];
    }
  }
  arr.push(temp);

  return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
I mean, it actually works for the above example, but not for anything else?
Christopher McCormack
@cmccormack
Aug 04 2017 18:42
@EpicTriffid didn't we already answer this above?
Object.keys returns an array
you got lucky in that it seems hasOwnProperty will work with an array of a single element with a string
EpicTriffid
@EpicTriffid
Aug 04 2017 18:43
@cmccormack I can't seem to find the toher answers :/
Hmm, don't I want to be returning an array?
Christopher McCormack
@cmccormack
Aug 04 2017 18:44
what's this one called?
if (collection[i].hasOwnProperty(Object.keys(source))) { if source is ever more than a single property it won't work
kumquatfelafel
@kumquatfelafel
Aug 04 2017 18:45
@EpicTriffid Object.keys(source) returns an array of the keys found in source. It happens to work in the particular case you posted, but this is really more of a "fortunate accident" than anything, because your source happens to have only one key. If your source has more than one key, this breaks.
EpicTriffid
@EpicTriffid
Aug 04 2017 18:48
@kumquatfelafel hmm, so do i need it to cycle through source as well?
kumquatfelafel
@kumquatfelafel
Aug 04 2017 18:50
pretty much.
Christopher McCormack
@cmccormack
Aug 04 2017 18:50
yup
EpicTriffid
@EpicTriffid
Aug 04 2017 18:52
Riiiiiggghttt
Now, can I loop through it using the same for loop as collection?
Christopher McCormack
@cmccormack
Aug 04 2017 18:55
@EpicTriffid you can't use the same iterator but you could do the loop within the outer loop if you like
kumquatfelafel
@kumquatfelafel
Aug 04 2017 18:58
and remember, you only want the object if it matches all of the key/value pairs in source
EpicTriffid
@EpicTriffid
Aug 04 2017 18:59
@kumquatfelafel @cmccormack Right. Lemme get going on it. Thankyou!
CamperBot
@camperbot
Aug 04 2017 18:59
epictriffid sends brownie points to @kumquatfelafel and @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 573 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 1101 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 04 2017 19:00
@EpicTriffid gl
EpicTriffid
@EpicTriffid
Aug 04 2017 19:01
@cmccormack I'll need it!
Ogundele Olumide
@Lumexralph
Aug 04 2017 19:01
hey @cmccormack
Hello Everyone
Christopher McCormack
@cmccormack
Aug 04 2017 19:02
@Lumexralph heya!
Jason Luboff
@JLuboff
Aug 04 2017 19:02
Yo
Ogundele Olumide
@Lumexralph
Aug 04 2017 19:02
how're you? @cmccormack
@JLuboff hey bro
What's up?
Christopher McCormack
@cmccormack
Aug 04 2017 19:02
@Lumexralph great, looking forward to the weekend!
Jason Luboff
@JLuboff
Aug 04 2017 19:02
It's friday! Half way through the day
Ogundele Olumide
@Lumexralph
Aug 04 2017 19:03
@cmccormack yeah!
@JLuboff I'm in the future as always :smile:
Jason Luboff
@JLuboff
Aug 04 2017 19:04
True haha
Christopher McCormack
@cmccormack
Aug 04 2017 19:04
haha
kumquatfelafel
@kumquatfelafel
Aug 04 2017 19:04
So, for example...
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], {first: "Tybalt", last: "Capulet" }); 
//should return [{first : "Tybalt", last : "Capulet"}], whereas...
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], {first: "Smelly", last: "Capulet" }); 
//should return []
Ogundele Olumide
@Lumexralph
Aug 04 2017 19:05
been deep in node api blah blah
Jason Luboff
@JLuboff
Aug 04 2017 19:05
I finished my Nightlife App the other day.
Haven't started the Stock app quite yet
Ogundele Olumide
@Lumexralph
Aug 04 2017 19:07
i haven't gotten time yet for FCC project, working on another project.... @JLuboff how well have you worked with TDD and BDD?
hey bro @Lumexralph
EpicTriffid
@EpicTriffid
Aug 04 2017 19:07
@kumquatfelafel hmm, i feel like i'm missing something here with looping through my object. I've ran a second loop within the first labeled j, and then referenced that with the object.keys and its giving me blanks
Jason Luboff
@JLuboff
Aug 04 2017 19:07
@Lumexralph I haven't worked with either
Thomas Faller
@thomasfaller
Aug 04 2017 19:09

Hmmm so close on that Spinal Tap:

function replaceStr(str) {
  var newStr = str.replace(/\_*\s*([A-Z])/g,'-$1').toLowerCase();
  if (newStr[0] == "-") {
    return newStr.slice(1);
  } else return newStr;
}

Sadly replaceStr("Teletubbies say Eh-oh”) is returning "teletubbies say-eh-oh”
I’m only using * as connectors here but am I doing something wrong that the space is not replaced by a dash ? :/

Ogundele Olumide
@Lumexralph
Aug 04 2017 19:10
@JLuboff Okay.... How's champ and wife?
@kelechy brotherly
Christopher McCormack
@cmccormack
Aug 04 2017 19:10
@thomasfaller oh aren't matching on space + lowercase
kumquatfelafel
@kumquatfelafel
Aug 04 2017 19:11
@EpicTriffid post code
Kelechi Chinaka
@ke1echi
Aug 04 2017 19:11
hows it going? @Lumexralph
Jason Luboff
@JLuboff
Aug 04 2017 19:11
@Lumexralph Doing good. Get to see him today (ultrasound).
Stephen James
@sjames1958gm
Aug 04 2017 19:11
@kelechy This passed:
function facRecursion(value){
  if(value < 0) return 0;
  if(value <= 1) return 1;
  return value * facRecursion(value - 1);
}
Thomas Faller
@thomasfaller
Aug 04 2017 19:11
@cmccormack Hey Chris, can you explain that? I though including \s would replace any space with a -
Guderian Raborg
@hypercuber
Aug 04 2017 19:12
Can someone help me change this.update so that the squares grow from the center rather than corner:
https://codepen.io/hypercuber/pen/yoerwo?editors=0010
Stephen James
@sjames1958gm
Aug 04 2017 19:12
@thomasfaller Maybe [_\s]*
Ogundele Olumide
@Lumexralph
Aug 04 2017 19:12
@JLuboff awesome!
EpicTriffid
@EpicTriffid
Aug 04 2017 19:13

function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  var x;
  for (var i = 0; i < collection.length; i++) {
    for (x in source) {
      if (collection[i].hasOwnProperty(Object.keys(source[x]))) {
      arr.push(collection[i]);
      }
    }
  }  
  return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Christopher McCormack
@cmccormack
Aug 04 2017 19:13
@thomasfaller your regex doesn't just look for \s though
Stephen James
@sjames1958gm
Aug 04 2017 19:13
@EpicTriffid Your test needs to check key exists and values match
Ogundele Olumide
@Lumexralph
Aug 04 2017 19:13
@kelechy tired, need to finish my api routes, how're you?
Kelechi Chinaka
@ke1echi
Aug 04 2017 19:16
yea..fixed!!! @sjames1958gm
EpicTriffid
@EpicTriffid
Aug 04 2017 19:16
@sjames1958gm So is it currently not checking for the key?
Kelechi Chinaka
@ke1echi
Aug 04 2017 19:17
am ok, just learning how to code :smile: ...the bootcamp must be stressful @Lumexralph
Stephen James
@sjames1958gm
Aug 04 2017 19:18
You don't need both Object.keys and for (x in source) - x is the key
collection[i].hasOwnProperty(x) && collection[i][x] === source[x]
EpicTriffid
@EpicTriffid
Aug 04 2017 19:22
@sjames1958gm Right, so that is checking that each object in collection has the property x (and x is looping through source)? Then it's checking if that property and value exists with source?
Ogundele Olumide
@Lumexralph
Aug 04 2017 19:22
@kelechy people dropped out, very crazy stuffs
Stephen James
@sjames1958gm
Aug 04 2017 19:22
@EpicTriffid yes
Kelechi Chinaka
@ke1echi
Aug 04 2017 19:23
:smile: :smile: @Lumexralph
EpicTriffid
@EpicTriffid
Aug 04 2017 19:24
@sjames1958gm So, if I was to use Object.keys, how would it look?
Stephen James
@sjames1958gm
Aug 04 2017 19:26
@EpicTriffid Assign Object.keys to a variable then use a for loop
var keys = Object.keys(source);
for (var k = 0; k < keys.length; k++) {
   if (collection[i].hasOwnProperty(keys[k]) && collection[i][keys[k]] === source[keys[k]]
}
Frank
@Frankbono
Aug 04 2017 19:26
Hi, can someone help me. I am working on my weather app and I am having a problem with switch back and forth between celsius and fahrenheit. I can get it to switch but I can’t get it to switch back. Can someone help me. Here’s my code
https://codepen.io/Frankbono/pen/prNozW?editors=1010
Stephen James
@sjames1958gm
Aug 04 2017 19:27
@Frankbono - Should you be using fTemp twice?
        if (tempSwitch === false) {
          $("#cTemp").html(fTemp);
          tempSwitch = true;
        } else {
          $("#cTemp").html(fTemp);
          tempSwitch = false;
        }
Frank
@Frankbono
Aug 04 2017 19:28
@sjames1958gm I’m not sure
Christopher McCormack
@cmccormack
Aug 04 2017 19:28
you shouldn't, that's why he asked :)
Stephen James
@sjames1958gm
Aug 04 2017 19:28
@Frankbono Well you need to use a different value for the if/else
Frank
@Frankbono
Aug 04 2017 19:29
@sjames1958gm Not sure what to do
Corentin Whyte
@CorySW
Aug 04 2017 19:29
I have no idea how to start the logic part of the simon game what would be good functions I've already put an init function and a function to output a random number to make a pattern
Stephen James
@sjames1958gm
Aug 04 2017 19:30

@Frankbono Create two vars one for F and one for C - then switch them in the click handler

      var fTemp = "Temperature: " + (fahrtemp + "˚" + " fahrenheit")
      var cTemp = "Temperature: " + temperature + "˚" + " celsius"

and

       if (tempSwitch === false) {
          $("#cTemp").html(fTemp);
          tempSwitch = true;
        } else {
          $("#cTemp").html(cTemp);
          tempSwitch = false;
        }
EpicTriffid
@EpicTriffid
Aug 04 2017 19:30
Should this exercise really be taking me this long?
Stephen James
@sjames1958gm
Aug 04 2017 19:31
@EpicTriffid It is a challenging one.
@sjames1958gm You may have to swap the if / else values
Thomas Faller
@thomasfaller
Aug 04 2017 19:31
I’m advancing here but I can’t still get my expression to target a whitespace that’s before a lowercase letter:
https://share.squarespace.com/471t0j352r0u
Any thougts on what I should add to my regex?
Image 2017-08-04 at 8.29.35 PM.png
Frank
@Frankbono
Aug 04 2017 19:35
@sjames1958gm I did what you said and nothing works when I click the button
EpicTriffid
@EpicTriffid
Aug 04 2017 19:36
Hmm, so when using if (collection[i].hasOwnProperty(x) && collection[i][x] === source[x]), how does source[x] reference the values rather than the properties?
Frank
@Frankbono
Aug 04 2017 19:36
@sjames1958gm Never mind, it works, I just had to change the ID in the HTML
Stephen James
@sjames1958gm
Aug 04 2017 19:36
@Frankbono :+1:
Frank
@Frankbono
Aug 04 2017 19:36
@sjames1958gm Once again, Thank you Stephen!!!
CamperBot
@camperbot
Aug 04 2017 19:36
frankbono sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8245 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 04 2017 19:36
@EpicTriffid x is a key so source[x] is the value
@Frankbono np
Thomas Faller
@thomasfaller
Aug 04 2017 19:40
a small step forward
str.replace(/[_\t]*\s*([A-Z])*(\s[a-z])/g,'-$1’)
Nadia
@nadiaschutz
Aug 04 2017 19:41
@cmccormack hey i solved it
Christopher McCormack
@cmccormack
Aug 04 2017 19:41
@nadiaschutz awesome, sorry we couldn't be more help :D
Nadia
@nadiaschutz
Aug 04 2017 19:42
@cmccormack it was a simple solution ...just to put options.length =0 to the end of the function
Christopher McCormack
@cmccormack
Aug 04 2017 19:43
@nadiaschutz hmm that isn't a great solution - length should not be manipulated directly
Nadia
@nadiaschutz
Aug 04 2017 19:43
@cmccormack why not?
Thomas Faller
@thomasfaller
Aug 04 2017 19:43
almost there…
Anyone know why this one is taking away the s in say when it returns the new string?
https://codepen.io/thomasfaller/pen/RZoMoN
Christopher McCormack
@cmccormack
Aug 04 2017 19:45
@nadiaschutz it usually means you aren't looking at the problem correctly. Length is a property that should only be changed as items are added or removed from an array
EpicTriffid
@EpicTriffid
Aug 04 2017 19:45
@sjames1958gm I still don't understand why x refers to the key, but then putting source[x] refers to the value. For example, when you've got { last: "Capulet" } shouldn't source[x] refer to "last" seeing as that's the key?
Stephen James
@sjames1958gm
Aug 04 2017 19:45
@EpicTriffid When you do for (x in source) x will be each key in order.
Nadia
@nadiaschutz
Aug 04 2017 19:45
@cmccormack that what i am doing....removing the items...reseting them to 0...right?
Stephen James
@sjames1958gm
Aug 04 2017 19:46
@EpicTriffid source["last"] is the same as source[x] which is "Capulet"
Nadia
@nadiaschutz
Aug 04 2017 19:46
@cmccormack and when the new items come the arr will be cleared
Christopher McCormack
@cmccormack
Aug 04 2017 19:46
@nadiaschutz I'm still not sure why your options keep growing, I don't think you showed enough code to determine that. if you want to clear an array, probably better to do something like options = []
EpicTriffid
@EpicTriffid
Aug 04 2017 19:49
@sjames1958gm oh for god's sakes, I don't know why my brain was betraying me. Source[x] tells it to look WITHIN 'last'. My head was telling me it is was just looking as the key name itself
Stephen James
@sjames1958gm
Aug 04 2017 19:49
@EpicTriffid Break time :)
Christopher McCormack
@cmccormack
Aug 04 2017 19:49
@EpicTriffid that's the worst kind of betrayal, the kind against you!
EpicTriffid
@EpicTriffid
Aug 04 2017 19:51
@cmccormack I know right?!
Jim Tryon
@jimtryon
Aug 04 2017 19:53
Oh, the small mistakes that take hours to find
Welcome to the art of programming!
EpicTriffid
@EpicTriffid
Aug 04 2017 20:01
Argh! So close! I can get 2 out 4 of the examples they give you
EpicTriffid
@EpicTriffid
Aug 04 2017 20:02
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  for (var i = 0; i < collection.length; i++) {
    for (var x in source) {
      if (collection[i].hasOwnProperty(x) && collection[i][x] === source[x]) {
      arr.push(collection[i]);
      }
    }
  }
  return arr;
}
Think its the single property thing again