These are chat archives for MontCode/GeneralChat

5th
Aug 2016
Eric Phy
@SimplyPhy
Aug 05 2016 13:59
@davidjcastner I think I asked this exact question before, but I find myself stuck on it again: how can I take the string stored inside a variable, and make it the var name (e.g.var ‘this’ = new HappyFace) for a new instance of a class?
var happy = “ImSoHappy”;
var “ImSoHappy” = new HappyFace();
something like that
obviously without the “” in the var name, it’s just there to point out that it came from the string inside happy
David Castner
@davidjcastner
Aug 05 2016 14:02
that functionality doesn't exist, you could store it in an object though and use that
var App = {};
var happy = 'ImSoHappy';
App[happy] = new HappyFace();
Eric Phy
@SimplyPhy
Aug 05 2016 14:03
hmmm
how would I log the instance then?
David Castner
@davidjcastner
Aug 05 2016 14:04

you can then even access it like so:

App.ImSoHappy instanceof HappyFace; // true

but the correct way to access a variable that you define like this is:

App[happy]

@SimplyPhy what do you mean by

how would I log the instance then?

Eric Phy
@SimplyPhy
Aug 05 2016 14:05
console.log(App.ImSoHappy);
except, a version that works
like how can i access that instance? App.ImSoHappy doesn’t seem to do it
David Castner
@davidjcastner
Aug 05 2016 14:06
you can use
console.log(App[happy]);
Eric Phy
@SimplyPhy
Aug 05 2016 14:07
hmm, not working for me inside codepen right now..
David Castner
@davidjcastner
Aug 05 2016 14:07
save codepen and send me link
Eric Phy
@SimplyPhy
Aug 05 2016 14:08
oh i didn’t define the constructor function, i think the issue is
muhaha
it works :D
interesting solution, probably simple but i love it :D
This message was deleted
thanks @davidjcastner
MontBot
@MontBot
Aug 05 2016 14:10
simplyphy sends brownie points to @davidjcastner :sparkles: :thumbsup: :sparkles:
:cookie: 354 | @davidjcastner |http://www.freecodecamp.com/davidjcastner
Eric Phy
@SimplyPhy
Aug 05 2016 14:10
that’s better :P
David Castner
@davidjcastner
Aug 05 2016 14:11
no problem make sure to use App[happy] syntax and NOT App.ImSoHappy. It's clearer how you are defining the variable name, just wanted to point out that you access it like that
Eric Phy
@SimplyPhy
Aug 05 2016 14:12
that’s really awesome, i’m going to use that to store form data into localStorage where the course[i].section[j].segment[k] === the localStorage object name :D
oh wait, I thought App[happy] == App.ImSoHappy ?
David Castner
@davidjcastner
Aug 05 2016 14:13
yes they are technically equivalent, but it's considered bad coding practice to use the latter
since if someone goes to look at your code, including yourself later on, and that person wanted to see where App.ImSoHappy is defined they wouldn't be able to find it
Eric Phy
@SimplyPhy
Aug 05 2016 14:15
hmm, because ImSoHappy is itself a variable value, yes?
David Castner
@davidjcastner
Aug 05 2016 14:16
yes
Eric Phy
@SimplyPhy
Aug 05 2016 14:16
right, I’m on the verge of understanding that … xD
I was hoping to do away with object[property] syntax altogether aside from being able to read it, but yeah it’s definitely better in this situation...
David Castner
@davidjcastner
Aug 05 2016 14:19
now if you define your app like this:
// way one
var HappyFace = function() {};

var App = {
    ImSoHappy: new HappyFace()
};

// semantic way to access the variable this way
console.log(App.ImSoHappy instanceof HappyFace); //true



// way two
var App = {};
var happy = 'ImSoHappy';
App[happy] = new HappyFace();

// semantic way to access the variable this way
console.log(App[happy] instanceof HappyFace); //true
yes the reason for accessing it using the object[property] syntax is because the property name itself is a variable
hope that makes sense
Eric Phy
@SimplyPhy
Aug 05 2016 14:22
yup, i’m still grappling with it somewhat, but i’m digesting it
coping with the fact that obj[prop] !== obj.prop in all situations
namely, when prop === defined; // true, i guess
Owen Winkler
@ringmaster
Aug 05 2016 14:24
Wait… When is obj[prop] !== obj.prop?
David Castner
@davidjcastner
Aug 05 2016 14:25
yes
var HappyFace = function() {};

var App = {};
var happy = 'ImSoHappy.hello';
App[happy] = new HappyFace();

// this explains a case where the obj[prop] !== obj.prop
console.log(App[happy] instanceof HappyFace); //true
console.log(App[happy]); // {}
console.log(App.ImSoHappy.hello); // TypeError: Cannot read property 'hello' of undefined
Eric Phy
@SimplyPhy
Aug 05 2016 14:25
the answer to your question @ringmaster is right above where you asked it
a more complete answer to your question is contained within this most conversation
Owen Winkler
@ringmaster
Aug 05 2016 14:26
Oh, a variable vs a literal?
David Castner
@davidjcastner
Aug 05 2016 14:26
mhmm
Eric Phy
@SimplyPhy
Aug 05 2016 14:26
:(
Owen Winkler
@ringmaster
Aug 05 2016 14:26
Ok. Was worried my whole world was turning upside-down there for a minute. Please carry on.
Eric Phy
@SimplyPhy
Aug 05 2016 14:27
haha i was worried a tad too, though my concerns were better warranted, given my previous worldview
@davidjcastner has a way of ruining my life :P
David Castner
@davidjcastner
Aug 05 2016 14:27
hahaha whoops
hope that last example clears up why to use one syntax over the other
Eric Phy
@SimplyPhy
Aug 05 2016 14:31
in this situation, yeah definitely
thanks again @davidjcastner
MontBot
@MontBot
Aug 05 2016 14:31
simplyphy sends brownie points to @davidjcastner :sparkles: :thumbsup: :sparkles:
:warning: simplyphy already gave davidjcastner points
Eric Phy
@SimplyPhy
Aug 05 2016 14:31
damnit, more cookies!
David Castner
@davidjcastner
Aug 05 2016 14:31
no problem!
don't worry about the montbot
Eric Phy
@SimplyPhy
Aug 05 2016 14:31
COOKIES
David Castner
@davidjcastner
Aug 05 2016 14:31
lol
I'm on a diet don't about sending me more cookies
Owen Winkler
@ringmaster
Aug 05 2016 14:32
I’m unsure why, if you initially used happy=‘foo’; App[happy] = bar; you would ever try to use App.foo directly, anyway. That part doesn’t make sense to me. ¯\(ツ)
Eric Phy
@SimplyPhy
Aug 05 2016 14:33
because i’m an inexperienced programmer who decided he would exclusively use dot notation for object property access, prior to this revelation
Owen Winkler
@ringmaster
Aug 05 2016 14:33
Oh. Heh. Well, now you’ve leveled up. ;)
Eric Phy
@SimplyPhy
Aug 05 2016 14:34
:D
speaking of leveling up, I discovered codefights.com two nights ago..neat for me :D
also, I get $1000 if anyone i refer beats a company sponsored bot, so let me know if you want to give it a go and i’ll split the winnings with you :D
David Castner
@davidjcastner
Aug 05 2016 14:38
what is it?
Eric Phy
@SimplyPhy
Aug 05 2016 14:38
oh wait, you have to beat a company’s bot, apply to a position at that company, and get accepted…then i get $1000 xD
Owen Winkler
@ringmaster
Aug 05 2016 14:39
I was going to say, “Give me a link,” but, yeah… don’t need a job. :)
David Castner
@davidjcastner
Aug 05 2016 14:39
what are you tested on?
Eric Phy
@SimplyPhy
Aug 05 2016 14:40
you basically are given programming challenges of varying difficulty (sometimes a bug, sometimes missing piece of program, something solve challenge, etc), and you compete with either a bot or a person to produce a program that passed all of the visible (and hidden) tests that are run against your program to see how comprehensively you solved the challenge
David Castner
@davidjcastner
Aug 05 2016 14:41
hmm, how long does it usually take?
Eric Phy
@SimplyPhy
Aug 05 2016 14:41
each “fight” involves 3 challenges, and you get points based on how many tests your program successfully passes
if you and the bot/person ty in points, the winner is decided by who did it faster, overall
last night the one i did took 1.5 mins for the first vhallenge, 55 mins for the second challenge (because i’m an idiot and had to think through how to build a factorial calculator), and the third took 1.5 mins
the night before, i had an easy one that took like 5-10 mins total, and after that i did one where i solved the first challenge really fast, and solved the second one in about 15 minutes, but one of the damn “hidden” tests (they show you some tests they run against your program, and you can create as many custom tests as you want, but they never show you the hidden tests) kept failing
i still have no idea why that one damn test kept failing, i spent like 2 hours trying every combination possible, and i couldn’t pass that one damn test. I got to the point where i honestly thought it was bugged
Eric Phy
@SimplyPhy
Aug 05 2016 14:46
oh shit
it just occurred to me that the bot i was facing with that one challenge was the asana company bot xD
i thought it was just a default bot (there are 6 standard bots, presumably each more challenging than the prior)
David Castner
@davidjcastner
Aug 05 2016 14:50
hmm I'll probably give it a go when I get some free time
Eric Phy
@SimplyPhy
Aug 05 2016 14:51
i like it :D
the challenges are actually usually interesting, at least in my experience thus far
plus we can challenge eachother, and you can create your own bot, and create teams, etc :smiling_imp:
David Castner
@davidjcastner
Aug 05 2016 14:53
I'll message you if I sign up
Eric Phy
@SimplyPhy
Aug 05 2016 14:55
cool, i use github to login, so same username there
https://codefights.com/signup/2GPCrETsJ7cJRCYaH/main that’s my custom invite URL if @all want it
https://codefights.com/tournaments/pM6uRn4H3osCbiGzq < this 10 min tournament begins basically now, if you want to try it :D
David Castner
@davidjcastner
Aug 05 2016 15:02
in the middle of something at work
Eric Phy
@SimplyPhy
Aug 05 2016 15:02
lols @me trying to compete in this tourny xD

Given a rectangular matrix of integers and integers n and m, we are looking for the submatrix of size n × m that has the maximal sum among all submatrices of the given size.

Example

For

matrix = [[1, 12, 11, 10],
[4, 3, 2, 9],
[5, 6, 7, 8]]
n = 2 and
m = 1, the output should be
maxSubmatrixSum(matrix, n, m) = 19.

This message was deleted
Eric Phy
@SimplyPhy
Aug 05 2016 15:08
This message was deleted
Owen Winkler
@ringmaster
Aug 05 2016 17:17
Woo, beat Botasana.
Lily Romano
@Lilyheart
Aug 05 2016 17:21
:thumbsup:
kevincauto
@kevincauto
Aug 05 2016 17:58
Thanks @ringmaster and @davidjcastner for your advice about the freelance job. I was able to bill an amount that worked for both me and the company. I completed the project today: http://codepen.io/kevincauto/pen/kXRmoz
Owen Winkler
@ringmaster
Aug 05 2016 17:59
Nice work!
kevincauto
@kevincauto
Aug 05 2016 18:00
Thank you!
David Castner
@davidjcastner
Aug 05 2016 18:05
@kevincauto nice work!