These are chat archives for FreeCodeCamp/HelpJavaScript

19th
Feb 2018
abraham anak agung
@padunk
Feb 19 00:47

Hi All, I want to ask how Date works. Why is this not Invalid Date?

var d = 'February 31, 2012';

console.log(new Date(d)); //2012-03-01T17:00:00.000Z

Because of elapsed year?

Tai Jones
@taiJones00
Feb 19 01:37
function palindrome(str) {
  // Good luck!
  //Setting str to lowerCase
  str = str.toLowerCase();

  // Take out the bad contents of str and replace them with nothing
  //re assign str to itself minus the spaces, non-digits, and non-letters
  str = str.replace(/\s\D\W/gi, "");

  // Reversing copyStr and assigning the value of str to it
  copyStr = str.split("").reverse().join("");

  // The spot for comparing copyStr with str
  return str;
}



palindrome("RaCe car");
I feel i'm on the right track. Am I using .replace right?
Roger Colquehuanca Calcina
@rogergcc
Feb 19 01:39
@padunk how is like this
var date = new Date("March 4, 2017");
console.log(date);
Tai Jones
@taiJones00
Feb 19 01:43
I feel like the only character not being recognized is the space @VaseJS
Ken Haduch
@khaduch
Feb 19 01:43
@taiJones00 - you can put a console.log(str) after your .replace to see what result you are getting.
VaseJS
@VaseJS
Feb 19 01:44
@taiJones00 huh? I didn’t know about this room. I had to join it. what do you mean i’m not recognized?
Roger Colquehuanca Calcina
@rogergcc
Feb 19 01:44
return (inputString == inputString.split('').reverse().join(''));
Ken Haduch
@khaduch
Feb 19 01:44
@taiJones00 - also, you should group your characters together with [] because you want to treat each character individually, not search for a sub-string that matches your expression.
Tai Jones
@taiJones00
Feb 19 01:45
ohh. That actually might fix it
like .replace(/[\s\D\W]/gi, "");
Actually it looks like this is preventing anything from showing up in the console
Tai Jones
@taiJones00
Feb 19 01:50
If I don't use [] then I get output in the console
@VaseJS Like in the case of palindrome("0_0 (: /-\ :) 0-0") it will take out every unwanted character except for space
Ken Haduch
@khaduch
Feb 19 01:53
@taiJones00 - your expression might be a little bit off... try removing the \D - that would be matching characters that are non-digits. And you want to keep some non-digits, like the alphabetic characters... :)
VaseJS
@VaseJS
Feb 19 01:54
oh, i realize what you mean now :D
ha! read your message to fast
Tai Jones
@taiJones00
Feb 19 01:55
It's okay @VaseJS
I didn't think of that @khaduch Nice thinking
VaseJS
@VaseJS
Feb 19 01:56
@taiJones00 go to my regex playground https://regexr.com/
(i did not create it, just use it to build regex)
Tai Jones
@taiJones00
Feb 19 01:59
It works. I should save that regEx link. Thank you @VaseJS
It works. I should save that regEx link. Thank you @VaseJS
CamperBot
@camperbot
Feb 19 01:59
taijones00 sends brownie points to @vasejs :sparkles: :thumbsup: :sparkles:
:cookie: 529 | @vasejs |http://www.freecodecamp.org/vasejs
VaseJS
@VaseJS
Feb 19 01:59
@taiJones00 :+1:
VaseJS
@VaseJS
Feb 19 02:16
so this is where everyone else hangs out
the not so secret room
AbrisM
@AbrisM
Feb 19 02:21
lol
abraham anak agung
@padunk
Feb 19 02:32
@rogergcc it still the same. Feb 31, 2012 is a valid date, even it output is 2012-03-01. Just curious why that date is a valid one while Feb 32 is Invalid
Fabien SHAN
@X140hu4
Feb 19 06:12
Hi Guys, I am working on the computer sequence for the simon game. I have trouble replaying the sequence. Using a for loop going through the sequence it does not play them in sequence. The sequence should be played one after the other. Any hint to go forward?
Fabien SHAN
@X140hu4
Feb 19 06:41
Hi guys, I am working on the Simon project. I am currently working on the computer sequence. I have the sequence saved in an array and I tried looping through that array to replay the sequence. However it seems to fire only once. Any hint on things I could search and explore to do this?
Brad
@bradtaniguchi
Feb 19 06:49
@X140hu4 Hard to say without any code
Fabien SHAN
@X140hu4
Feb 19 06:50
    for (var i = 0, n = computerSequence.length; i < n; i++) {
        playButton(computerSequence[i]);
    }
Basically this is the specific piece I have atm
The playButton function is taking an argument refering to the button to play and plays it.
Markus Kiili
@Masd925
Feb 19 06:57
@X140hu4 Nothing wrong with the loop syntax.
Fabien SHAN
@X140hu4
Feb 19 06:59
Its just playing all the sounds at the same time ^^;
abraham anak agung
@padunk
Feb 19 07:04
@X140hu4 i think you need setInterval to play the computer sequence
Markus Kiili
@Masd925
Feb 19 07:11
@X140hu4 Something like this would make the calls with second intervals:
for (var i = 0, n = computerSequence.length; i < n; i++) {
    (function(val){
      setTimeout(function(){playButton(val)},i*1000)
    })(computerSequence[i]);
}
Fabien SHAN
@X140hu4
Feb 19 07:12
@Masd925 Ok great. I will try that :)
Claudio Restifo
@Marmiz
Feb 19 09:16
Any suggestion on filtering/removing out values from an object (besides delete Object.value)
Markus Kiili
@Masd925
Feb 19 09:18
@Marmiz I think that delete is the only way. How you iterate over the keys is another question.
Another way is iterating the keys and generating a new object with filtered keys etc.
Claudio Restifo
@Marmiz
Feb 19 09:20
@Masd925 let me rephrase, any good iteration keys/ removing couple suggestion?
I was thinking of:
[valesToRemoveArray].map(r => delete Object[r])

iterating the keys and generating a new object with filtered keys etc.

thought about it but seems more convoluted

Markus Kiili
@Masd925
Feb 19 09:21
@Marmiz You should use forEach there.
Claudio Restifo
@Marmiz
Feb 19 09:24
ye. good call
Markus Kiili
@Masd925
Feb 19 09:24
@Marmiz I think that would be a good way.
Claudio Restifo
@Marmiz
Feb 19 09:25
just that seems convoluted since I also want to keep an immutability pattern so I have to make a copy of the object first, then remove from the copy
Markus Kiili
@Masd925
Feb 19 09:33
@Marmiz Make a copy and remove keys, or filter a list of keys and make a new object from it.
Claudio Restifo
@Marmiz
Feb 19 09:50

@Masd925

const o = {
  a: 1,
  b: 2,
  c: 3,
};
const x = ['a', 'c'];

// v1
const cp = Object.assign({}, o);
x.forEach(r => delete cp[r]);

// v2
const k = Object.keys(o).filter(r => x.indexOf(r) === -1 );
const cp = {};
k.forEach(v => cp[v]= o[v])

Think v1 is more readable at a first glance.

imho
Markus Kiili
@Masd925
Feb 19 09:52
@Marmiz I agree.
Denis McDonald
@denismcdonald
Feb 19 10:00
var myString = "Test #100!";
console.log(myString.replace(/[0-9]/g, "").length);
Hi all. I don't suppose anyone could explain why the above returns a value of 7 instead of 3, could they? I'm a bit bamboozled. I know how to find the 3 digits in the string (by inserting a ^ before the 0-9), but I don't know why that works, when it seems to be asking for the reverse of what I want.
Markus Kiili
@Masd925
Feb 19 10:01
@denismcdonald That replace method returns "Test #!".
abraham anak agung
@padunk
Feb 19 10:01
@denismcdonald do you want the length of the number? your replace, replacing number with empty
Denis McDonald
@denismcdonald
Feb 19 10:02
Yes @Masd925, whereas I would have thought it would return 100.
Markus Kiili
@Masd925
Feb 19 10:02
@denismcdonald It returns a new string where numbers are replaced with empty strings and thus effectively removed.
Denis McDonald
@denismcdonald
Feb 19 10:04
I'm just trying to digest that... ! (Appreciate the help.)
Denis McDonald
@denismcdonald
Feb 19 10:09
Oh, I get it now! Boy, was I stuck on that. Sorry for being slow, and thanks again, @Masd925
CamperBot
@camperbot
Feb 19 10:09
denismcdonald sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4696 | @masd925 |http://www.freecodecamp.org/masd925
Adel
@AdelMahjoub
Feb 19 13:55
I'm looking for some feedbacks, if this is 'playable' front invaders, far from polished, the basic concept is there
alpox
@alpox
Feb 19 14:07
@AdelMahjoub looks good :) on mobile i cannot move the ship though
I like the smoke animation
Adel
@AdelMahjoub
Feb 19 14:08
@alpox thanks, controls for touch screens not ready yet
CamperBot
@camperbot
Feb 19 14:08
adelmahjoub sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1543 | @alpox |http://www.freecodecamp.org/alpox
CamperBot
@camperbot
Feb 19 14:49
taijones00 sends brownie points to @vasejs :sparkles: :thumbsup: :sparkles:
:cookie: 531 | @vasejs |http://www.freecodecamp.org/vasejs
h1tag
@h1tag
Feb 19 15:43
@AdelMahjoub it's definitely playable, I like the UI and the music, and I'm enjoying the gameplay so far (makes me wanna' search for a similar game on my mobile)
I got a score of 3995 :satisfied:
JLuboff
@JLuboff
Feb 19 16:17
:wave:
Christopher McCormack
@cmccormack
Feb 19 16:28
@JLuboff yo!
JLuboff
@JLuboff
Feb 19 16:28
@cmccormack Whats good?
Christopher McCormack
@cmccormack
Feb 19 16:28
I hear Black Panther is pretty good despite some plot holes and logical flaws
JLuboff
@JLuboff
Feb 19 16:28
Haha
Christopher McCormack
@cmccormack
Feb 19 16:31
What about yourself @JLuboff
JLuboff
@JLuboff
Feb 19 16:33
Just fixed an user reported error on my Fleet Management application. Got our new phones are worked deployed (first day using them) and going to continue on with my other project!
Kaz Baig
@kbaig
Feb 19 16:36
@cmccormack I tried watching it this weekend but it was sold out for Sat/Sun
Christopher McCormack
@cmccormack
Feb 19 16:36
@JLuboff man you are just killing it aren't you
@kbaig dang that busy? We'll probably go see it next weekend
@JLuboff oh I saw Hamilton at ASU Gammage as well, was really good
JLuboff
@JLuboff
Feb 19 16:49
@cmccormack I'd like to think so.. but I didn't do much for the new phones haha
Christopher McCormack
@cmccormack
Feb 19 16:49
@JLuboff don't tell your boss that
JLuboff
@JLuboff
Feb 19 16:49
@cmccormack He's the one who set them up hahaha
Christopher McCormack
@cmccormack
Feb 19 16:50
ohhh
haha
JLuboff
@JLuboff
Feb 19 16:50
But he knows what I've been working on so its all good
Christopher McCormack
@cmccormack
Feb 19 16:52
I would hope so hehe
JLuboff
@JLuboff
Feb 19 16:52
I mean.. you'd be surprised
Christopher McCormack
@cmccormack
Feb 19 16:52
haha
JLuboff
@JLuboff
Feb 19 16:54
@cmccormack What're you working on today?
Christopher McCormack
@cmccormack
Feb 19 16:55
Right now working on our new Internet VPN environment build which we're hoping to have deployed by the end of the month
Trying to figure out which platform is best by building fake tunnels and shoving traffic over it, kind of fun to learn some new stuff
JLuboff
@JLuboff
Feb 19 16:57
Ya sounds like it
Do you use any sort of ISP tunnel routing (i.e MPLS or NLAN)?
Kaz Baig
@kbaig
Feb 19 16:58
@cmccormack yeah im on MoviePass now so I can't even buy tickets in advance lol
Christopher McCormack
@cmccormack
Feb 19 16:59
is that the $10 a month service?
Kaz Baig
@kbaig
Feb 19 16:59
That was in Chicago though. Should be a lot less busy in Champaign this weekend
Yes it is
Christopher McCormack
@cmccormack
Feb 19 16:59
If there were more than 1 good movie a month I could see how that was worth it
Kaz Baig
@kbaig
Feb 19 17:00
Well on the off chance that I only go to one movie a month, I still break even / save a couple bucks
JLuboff
@JLuboff
Feb 19 17:00
....here I am still waiting to see Star Wars :(
Kaz Baig
@kbaig
Feb 19 17:00
My gf got her parents a 3 month subscription for xmas and they've seen literally about a dozen movies already
JLuboff
@JLuboff
Feb 19 17:11
@cmccormack So I started looking at express-validation and.. curious.. would you use it in a production environment or just development?
Christopher McCormack
@cmccormack
Feb 19 17:35
@JLuboff I would use it in production yeah, not sure why you wouldn't. The only things I use that are considered development I use along with development flags, like using webpack-dev-server or dev environment variables
Quantomistro3178
@Quantomistro3178
Feb 19 17:53
/[aeiou]/ is this the correct RegExp for vowels?
nevermind
JLuboff
@JLuboff
Feb 19 17:58
@cmccormack I guess I wasn't fully understanding it (or maybe comparing it to the past when I learned a little about mocha?)
Christopher McCormack
@cmccormack
Feb 19 17:59
@JLuboff I'm not sure, I could be wrong but it doesn't appear to be something you couldn't use in prod
JLuboff
@JLuboff
Feb 19 18:00
@cmccormack Thanks. May ask you for help later on when I implement it
CamperBot
@camperbot
Feb 19 18:00
jluboff sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1324 | @cmccormack |http://www.freecodecamp.org/cmccormack
Christopher McCormack
@cmccormack
Feb 19 18:00
np - you can check my votery repo if you want to see how I used it, in my routes.js
JLuboff
@JLuboff
Feb 19 18:00
Will do
FlashHero
@FlashHero
Feb 19 19:07
what is UglifyJsPlugin suppose to do in webpack ? I added this plugin nothings seems to happen
Christopher McCormack
@cmccormack
Feb 19 19:08
@FlashHero it's supposed to reduce the size of your bundle after it's compiled by removing whitespace and changing names to shorter names
if I remember correctly that is
JLuboff
@JLuboff
Feb 19 19:09
@cmccormack From a quick glance at the npm page, you're correct. Essentially a compressor of sort
FlashHero
@FlashHero
Feb 19 19:14
@JLuboff @cmccormack so It's the same thing as running it in production mode ?
Adel
@AdelMahjoub
Feb 19 19:19
thanks @h1tag , good to read you like the gameplay
CamperBot
@camperbot
Feb 19 19:19
adelmahjoub sends brownie points to @h1tag :sparkles: :thumbsup: :sparkles:
:cookie: 918 | @h1tag |http://www.freecodecamp.org/h1tag
JLuboff
@JLuboff
Feb 19 19:20
@AdelMahjoub I also played it a little, seemed to work well :+1:
Christopher McCormack
@cmccormack
Feb 19 19:22
@FlashHero I believe it does more than the standard bundle, just try with and without it and see how it looks
Adel
@AdelMahjoub
Feb 19 19:23
@JLuboff thanks, on chrome desktop it render in 60fps, but some performance issues on some mobiles, only powerVr is rendering quite smoothly
CamperBot
@camperbot
Feb 19 19:23
adelmahjoub sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2334 | @jluboff |http://www.freecodecamp.org/jluboff
JLuboff
@JLuboff
Feb 19 19:25
I tried on Firefox and looked/played well
FlashHero
@FlashHero
Feb 19 19:28
@cmccormack @JLuboff thanks
CamperBot
@camperbot
Feb 19 19:28
flashhero sends brownie points to @cmccormack and @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 1325 | @cmccormack |http://www.freecodecamp.org/cmccormack
:star2: 2335 | @jluboff |http://www.freecodecamp.org/jluboff
Simon Cordova
@gbsimon87
Feb 19 19:55
Good evening
JLuboff
@JLuboff
Feb 19 19:55
Hey Simon
Simon Cordova
@gbsimon87
Feb 19 19:55
Hey how's it going, hows the code these days
JLuboff
@JLuboff
Feb 19 19:56
Going good. Working on a work project right now (Node/SQL based)
Simon Cordova
@gbsimon87
Feb 19 19:56
Nice, as am I actually, Node and Mongo mainly
You look the type of person that might have an answer to a question I've got lol
JLuboff
@JLuboff
Feb 19 19:57
I'd rather do things in Mongo but we already are so deep into SQL..well...there's no changing haha
Simon Cordova
@gbsimon87
Feb 19 19:57
Recommend a nice and easy way to create a javascript hook which removes elements from your page as well as event listeners?
Never done SQL, I hear it's a whole other monster
Adel
@AdelMahjoub
Feb 19 19:59
@gbsimon87 a relative of yours Cordova ?
JLuboff
@JLuboff
Feb 19 19:59
I'm still stuck in jQuery...so I'd just use empty() to remove elements..but not sure about removing event listeners. We'd probably want @forkerino or @sjames1958gm or maybe event @AdelMahjoub since he is around to answer :)
Simon Cordova
@gbsimon87
Feb 19 20:00
@AdelMahjoub not sure I follow...
JLuboff
@JLuboff
Feb 19 20:00
SQL can be challenging..but since I'm studying it right now anyhow, it's not too bad. I'm not having the best time with the npm package I'm using with it though. UIsing mssql but thinking I might chagne to sequilize (or however you spell it)
Simon Cordova
@gbsimon87
Feb 19 20:00
oh cordova apache haha
Adel
@AdelMahjoub
Feb 19 20:00
@gbsimon87 yeah, it is supposed to be a joke :laughing:
Simon Cordova
@gbsimon87
Feb 19 20:01
never heard of sequelize either, I'm honestly just starting to dive into databases and figured I'd start with Mongo...
@AdelMahjoub, would you happen to know a nice and easy way to create a javascript hook which removes elements from your page as well as event listeners?
Stephen James
@sjames1958gm
Feb 19 20:02
from empty() documentation
To avoid memory leaks, jQuery removes other constructs such as data and event handlers from the child elements before removing the elements themselves.
JLuboff
@JLuboff
Feb 19 20:03
Mongo is great, I really like it. Really easy to work with IMO. I'd recomend taking the M101JS course offered through Mongo University (its free!) @gbsimon87
@sjames1958gm ...so my recomendation (if using jQuery) would handle it?
Stephen James
@sjames1958gm
Feb 19 20:04
@JLuboff Seems so.
Simon Cordova
@gbsimon87
Feb 19 20:04
@sjames1958gm does that imply a negative effect? I won't be using jQuery either way myself.
@JLuboff thanks for the tip I'm going to give it a shot :)
CamperBot
@camperbot
Feb 19 20:04
gbsimon87 sends brownie points to @sjames1958gm and @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2336 | @jluboff |http://www.freecodecamp.org/jluboff
:star2: 8995 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
JLuboff
@JLuboff
Feb 19 20:04
@sjames1958gm Sometimes I amaze myself. Other times, I shake my head in disgust.. :D
Adel
@AdelMahjoub
Feb 19 20:04
@gbsimon87 unless you use some librairies or framework, there are a lot of ways to adress it I think
Simon Cordova
@gbsimon87
Feb 19 20:06
function execution (options) { 

  function someFunction(userID) {
    return 'someFunction'
  }

  function removeContainer() {
    if ( window.localStorage.getItem("PopupHasBeenDisplayed") !== "true"   ) {
      document.querySelector("#popup").style.display = 'block';
    }

  }

  return {
    remove: removeContainer
  }
}
Adel
@AdelMahjoub
Feb 19 20:07
I got he same problem recently using phaser, by just destroying objects, so I had to extend each Phaser class and destroy manually, tweens and events
Simon Cordova
@gbsimon87
Feb 19 20:07
I'm thinking something like that, but need to account for everything
Adel
@AdelMahjoub
Feb 19 20:08
and I finally end up using a pool of js objects, so I can reuse them without destroying, because the garbage collector was doing a rampage
Simon Cordova
@gbsimon87
Feb 19 20:09
Oh man, I didn't think it'd be so hard to get rid of the stuff you create.
Apart from elements and event listeners what else must one account for?
Adel
@AdelMahjoub
Feb 19 20:10
it depends on how many objects you will instantiate I think
what I found is that objects are not that cheap, so for example for bullets objects I reuse a pool of already instantiated objects
but that's in a game context, maybe different on other context
Muhammad Hasham
@MohammadHasham
Feb 19 20:17
anyone doing or did nightlife cordination backend project?
JLuboff
@JLuboff
Feb 19 20:17
Yes, I've done it
Adel
@AdelMahjoub
Feb 19 20:17
isn't that a summer project ?
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:02
hi black and white panthers
@JLuboff yow black panther are you good with es6?
Brad
@bradtaniguchi
Feb 19 21:04
@RoniqueRicketts What's up with es6?
JLuboff
@JLuboff
Feb 19 21:04
Depends on the es6 code we're talking about
Kaz Baig
@kbaig
Feb 19 21:05
hey its ur me ur brown panther
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:06

@bradtaniguchi hey white panther. If I have

const stats = {
  max: 56.78,
  standard_deviation: 4.34,
  median: 34.54,
  mode: 23.87,
  min: -0.75,
  average: 35.85
};
const half = (function() {
  "use strict"; 
  return function half({max, min}) {
    return (max + min) / 2.0;
  };

})();
console.log(stats); 
console.log(half(stats));

the obj with {max, min} are they now stored in a brand new obj or if I made changes to max or min will it change the main object max or min?

@JLuboff for you black panther it may be easy
@kbaig Yes brown panther. I am gold panther :D
Brad
@bradtaniguchi
Feb 19 21:09
@RoniqueRicketts After looking at how people do this in es5 (and I'm assuming how a pollyfill would work as well) i'd say its passed by reference, so its the same object being passed to the function. But for this function I'm not 100% sure if it matters it seems like the values wouldn't get modified either way as your just adding them
JLuboff
@JLuboff
Feb 19 21:09
Just running through with console.logs... I'd agree with @bradtaniguchi that it's a reference still
It's just pulling those keys as the parameters
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:11
@bradtaniguchi well this was taken from freecodecamp beta but what I wanted to know is if I adjusted max or reassign min then would it update the big object stats.
Abdulah Hamzic
@hamzicabdulah
Feb 19 21:11
Hey, guys. Anyone here who is really experienced in building web bots/web scraping using JavaScript?
Brad
@bradtaniguchi
Feb 19 21:12
@RoniqueRicketts Yea it should, if me an @jluboff are right haha, otherwise tell us were wrong XD
@hamzicabdulah How come (I'm curious :D)
Abdulah Hamzic
@hamzicabdulah
Feb 19 21:14
@bradtaniguchi I'll be working on a project that involves doing a lot of web automation. I actually have a few important general questions to which I'd like to hear answers from people experienced with this kind of stuff
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:15
@bradtaniguchi nothing is wrong I just wanted to know what's up with that object that we passed, Just wanted to know if it a reference or its a brand new object
Kaz Baig
@kbaig
Feb 19 21:15
@RoniqueRicketts
let a = 1;
let b = 2;

function half({max, min}) {
  max = 3;
  min = 4;
  return (max + min) / 2.0;
};

console.log(half({ max: a, min: b })); // 3.5
console.log(a, b); // 1 2
Abdulah Hamzic
@hamzicabdulah
Feb 19 21:15
It'd also be cool to have someone to turn to just in case I ever get stuck and can't find a solution to a problem
Kaz Baig
@kbaig
Feb 19 21:16
@RoniqueRicketts you're creating a new object inline, which happens to use values stored in other variables. I hope I'm understanding the q correctly
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:20
@kbaig thanks man.
CamperBot
@camperbot
Feb 19 21:20
roniquericketts sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 573 | @kbaig |http://www.freecodecamp.org/kbaig
Kaz Baig
@kbaig
Feb 19 21:20
@RoniqueRicketts pleasure :)
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:22
@kbaig did you also learn something out of this?
Kaz Baig
@kbaig
Feb 19 21:23
@RoniqueRicketts I did expect the behavior observed but wasn't 100% sure. More like 80% ;)
JLuboff
@JLuboff
Feb 19 21:23
@kbaig You're still referencing the original object just reassigning the values inside the function (if I'm understanding your example correctly)
Kaz Baig
@kbaig
Feb 19 21:27
@JLuboff @RoniqueRicketts actually, I'll change the example a bit:
let a = 1;
let b = 2;

const obj = { max: a, min: b };

function half({max, min}) {
  max = 3;
  min = 4;
  return (max + min) / 2.0;
};

console.log(half(obj)); // 3.5
console.log(obj); // { min: 1, max: 2 }
console.log(a, b); // 1 2
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:27
@JLuboff so are you implying that the scope of the object allows him to create are assign min and max?
Kaz Baig
@kbaig
Feb 19 21:28
There is no mutation occurring here. Even if you created an object inline to pass to the function half, it's not being mutated
JLuboff
@JLuboff
Feb 19 21:28
@kbaig I think you and I are thinking along the same lines
Kaz Baig
@kbaig
Feb 19 21:28
So it seems that within the function, the params max and min are locally scoped
(btw I verified my examples in the console)
Christopher McCormack
@cmccormack
Feb 19 21:30
I believe you are destructuring the object in the function parameters, not referencing it
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:33
let a = 1;
let b = 2;

const obj = { max: a, min: b, "it": "here" };

function half({max, min}) {
  console.log("max " + max + " min: "+ min); //{"max 1 min: 2"}
  max = 3;
  min = 4;
  return (max + min) / 2.0;
};

console.log(half(obj)); // 3.5
console.log(obj); // {it: "here", min: 1, max: 2 }
console.log(a, b); // 1 2
Well it doesn't update the max and min they are independent reference and it doesn't update the main object at all.
Kaz Baig
@kbaig
Feb 19 21:33
@cmccormack yep that's what I'm trying to demonstrate
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:34
watch ya, christ changed his pic, What is this lol
Kaz Baig
@kbaig
Feb 19 21:34
@RoniqueRicketts quick tip: you might find it convenient to replace console.log("max " + max + " min: "+ min) with console.log({max, min})
Christopher McCormack
@cmccormack
Feb 19 21:34
I have many faces
Brad
@bradtaniguchi
Feb 19 21:35
Interesting
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:35
@kbaig ya, I just wanted to be double sure. I am just here messing around trying to cement the concepts on ES6
@cmccormack your a white panther. :)
Christopher McCormack
@cmccormack
Feb 19 21:36
I didn't realize I could be labeled so easily!
Kaz Baig
@kbaig
Feb 19 21:37
@RoniqueRicketts I mean it's convenient and readable in the log if you log variables within objects using es6 syntax
Christopher McCormack
@cmccormack
Feb 19 21:37
but yeah I guess I'm pretty white :D
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:37
@cmccormack lol heheh. yes you can heheh. I am giving ya'll panther names. hehe. I think I like Gold Panther so thats me :)
Christopher McCormack
@cmccormack
Feb 19 21:37
Can I be blue panther?
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:37
@kbaig also I could have used backtick
Kaz Baig
@kbaig
Feb 19 21:38
you could but I still think just wrapping it in curly braces is the easiest way
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:38
@cmccormack Can I change my handle on here so I can be @goldpanther?
Christopher McCormack
@cmccormack
Feb 19 21:38
@RoniqueRicketts maybe? change it on github maybe?
Ronique Ricketts
@RoniqueRicketts
Feb 19 21:40
@cmccormack ill avoid trying
Tiago Correia
@tiagocorreiaalmeida
Feb 19 22:05
has anyone runned into this issue "'state' is not defined no-undef"
using create-react-app?
readed about it seems an issue with eslinter, just to be sure
Stephen James
@sjames1958gm
Feb 19 22:08
@tiagocorreiaalmeida you are probably referencing state without this
The second part is saying that the linter rule that is being violated is no-undef or
No undefined variables
Tiago Correia
@tiagocorreiaalmeida
Feb 19 22:09
export class AddPostPage extends React.Component {
    state = {
        timer: false
    };

    componentWillMount() {
        this.props.setMessagesToDefault();
    }

    componentWillUnmount() {
        if (this.state.timer !== false) clearTimeout(this.state.timer);
    }

    onSubmit = post =>
        this.props.addPost(post).then(() =>
            setTimeout(() => {
                if (!this.props.errorMessage)
                    this.setState(() => ({
                        timer: setTimeout(
                            () => this.props.history.push("/myposts"),
                            3000
                        )
                    }));
            })
        );
and hey @sjames1958gm
Stephen James
@sjames1958gm
Feb 19 22:10
Hey
Ronique Ricketts
@RoniqueRicketts
Feb 19 22:11
@sjames1958gm sup Silver Panther.
Stephen James
@sjames1958gm
Feb 19 22:11
Hey @RoniqueRicketts
Ronique Ricketts
@RoniqueRicketts
Feb 19 22:11
@sjames1958gm Whats up bruv?
Stephen James
@sjames1958gm
Feb 19 22:12
Chillaxin after work. Weather nice for first time in weeks.
@tiagocorreiaalmeida that first state is probably the culprit. Shouldn’t that be inside a constructor?
Ronique Ricketts
@RoniqueRicketts
Feb 19 22:15
@sjames1958gm lucky you I am still on the plantation.
Tiago Correia
@tiagocorreiaalmeida
Feb 19 22:16
there's a plugin from babel that comes builted in with create-react-app so we dont need the constructor and neither to bind the functions let me see if I pick the name, still just for testing will place the constructor, but it's strange I got this working in like more 10 places, still worht the try
Stephen James
@sjames1958gm
Feb 19 22:17
@tiagocorreiaalmeida hmm with state? Seems like it shouldn’t be a problem then
Kaz Baig
@kbaig
Feb 19 22:18
@sjames1958gm @tiagocorreiaalmeida while I do prefer defining state within the constructor, I've never had any problems defining it outside of the constructor
Tiago Correia
@tiagocorreiaalmeida
Feb 19 22:19
still trhows error with the constructor I guess its just what say's on google and need to downgrad the eslint version, I just dont get it works in 10 places doesnt works in 1
well
Christopher McCormack
@cmccormack
Feb 19 22:20
why would it throw an error within the constructor?
Did you use this.state in the constructor?
Tiago Correia
@tiagocorreiaalmeida
Feb 19 22:20
yup
Christopher McCormack
@cmccormack
Feb 19 22:28
@tiagocorreiaalmeida does create-react-app come with eslint?
Tiago Correia
@tiagocorreiaalmeida
Feb 19 22:32
y
for what I know
Christopher McCormack
@cmccormack
Feb 19 22:35
I'll be honest I haven't even bothered to install eslint on my current project, I'm sick of being told what I can do!!!!
and lazy
Tiago Correia
@tiagocorreiaalmeida
Feb 19 22:36
eheheh, im just not getting it, I have 10 components where I define the state the same away and in the last one I needed state it throwned an error, not friendly at all .D
Christopher McCormack
@cmccormack
Feb 19 22:42
Are all of your components setup the same way as well?
Tiago Correia
@tiagocorreiaalmeida
Feb 19 22:55
yeah @cmccormack
Christopher McCormack
@cmccormack
Feb 19 23:01
@tiagocorreiaalmeida weird :)
Stephen James
@sjames1958gm
Feb 19 23:30
@tiagocorreiaalmeida Is it your top-level component that is failing?
Tiago Correia
@tiagocorreiaalmeida
Feb 19 23:49
hey @sjames1958gm once again allready closed everything today, its the component im rendering for a specific url path