These are chat archives for FreeCodeCamp/HelpJavaScript

22nd
Jan 2019
Pagnito
@Pagnito
Jan 22 01:04
hey anyone familiar with the $push operator on mongo?
Brad
@bradtaniguchi
Jan 22 01:23
I think we've used that a big here and there in our project
Pagnito
@Pagnito
Jan 22 01:34
Screen Shot 2019-01-21 at 8.34.45 PM.png
is this like a recent update, cuz its really annoying this scrollbar has gotten too big and i can never read one liner code on sites anymore
Brad
@bradtaniguchi
Jan 22 01:35
What kinda app is that
Pagnito
@Pagnito
Jan 22 01:40
chrome
Brad
@bradtaniguchi
Jan 22 01:40
never woulda guessed
Christopher McCormack
@cmccormack
Jan 22 01:41
I have that problem with Chrome on Mac with some web frontends
like they design it for windows and never test or something
Pagnito
@Pagnito
Jan 22 01:41
i see, yea i think its something recent too, cuz i never had that problem before
Nate Mallison
@NJM8
Jan 22 01:44
Anyone know how to git log commits only from my branch. My branch was made from master and has had master merged in as there have been updates, so I'm looking to show just commits made to this branch.
Brad
@bradtaniguchi
Jan 22 01:49
@NJM8 Hmmm thats an interesting use-case
Nate Mallison
@NJM8
Jan 22 01:56
Seems like an obvious one to me. I make a feature branch of off master. I make a bunch of commits. I want to log those commits and see them without seeing the other 2000 commits from master
this seems to work: git cherry -v master feature
Brad
@bradtaniguchi
Jan 22 02:05
Yea I was pretty sure git had a way todo it, but I never thought about it nor did i know how todo it haha
Christopher McCormack
@cmccormack
Jan 22 02:46
@NJM8 would it make more sense to rebase your changes on master so your commits are at the top?
Nate Mallison
@NJM8
Jan 22 02:50
no
Ran into trouble doing that
Christopher McCormack
@cmccormack
Jan 22 02:55
what kind of trouble?
Riadh
@KWFE
Jan 22 03:16
I AM IN A BIG TROUBLE
Brad
@bradtaniguchi
Jan 22 04:59
@KWFE Trouble is my middle name :P
tundeiness
@tundeiness
Jan 22 10:41
errrm guys can someone help me check why my Hello isn't rendering? https://codepen.io/highness/pen/xmMMoG?editors=0110
Blauelf
@Blauelf
Jan 22 11:14
Case-sensitivity. React.Component and ReactDOM.
The error messages could have told you. First one causes a "no idea what this super-class is meant to be" (and you have exactly one super-class to check), the second "no idea what a ReactDom is".
tundeiness
@tundeiness
Jan 22 12:17
@Blauelf Thanks!!
Francois Beyers
@Blusoup
Jan 22 14:47

Im trying to write a function that will use an Object that has a key and a value shorthand for that key. I want to replace the key in a string with the shorthand value.
String eg:

"John_Smith_John_Doe_Kevin_Smith"

Object eg:

let nameShorthand = {
    John_Smith: 'js',
    John_Doe: 'jd',
    Kevin_Smith: 'ks'
}

so I want the string to look like this then:

"js_jd_ks"

Can anyone help me in how I would achieve this? Thank you

Tiago Correia
@tiagocorreiaalmeida
Jan 22 15:32
you loop the obj and concatenate each key value to a string followed by a _
you can use object.keys and reduce together for this one
Tiago Correia
@tiagocorreiaalmeida
Jan 22 15:55
or object.values, and join them by "_"
Object.values(nameShorthand).join("_");
Pagnito
@Pagnito
Jan 22 16:07
hey whats faster or better in mongo. If i attach _id to each blogPost record and then query a users posts with one find(_id: user.id) or use the relations with Schema.Types.ObjecId and in queries use populate?
Christopher McCormack
@cmccormack
Jan 22 16:11
populate makes additional requests, so it's up to you - it doesn't really add all that much in convenience if you ask me
Jason Luboff
@JLuboff
Jan 22 16:11
Morning
Christopher McCormack
@cmccormack
Jan 22 16:12
@JLuboff heya
Jason Luboff
@JLuboff
Jan 22 16:12
Whats happening
Christopher McCormack
@cmccormack
Jan 22 16:12
more work just flowing down, gonna be a busy few months :/
you?
Pagnito
@Pagnito
Jan 22 16:13
@cmccormack i see thnx
Jason Luboff
@JLuboff
Jan 22 16:13
Got into work a bit late...managed to spill my coffee on myself right before I was heading out. So...now back to writing tests I think
Christopher McCormack
@cmccormack
Jan 22 16:13
@JLuboff at least it wasn't when you got to work :)
Jason Luboff
@JLuboff
Jan 22 16:15
This is true.. spilled some on my leather/nubuk shoes though...not sure I'll be able to clean them very well but I'll check them out later when I get home
Christopher McCormack
@cmccormack
Jan 22 16:15
ouch
car spills are the worst, hate the smell of coffee lingering in the car
Jason Luboff
@JLuboff
Jan 22 16:16
I have the smell of coffee lingering on me...and I don't know where lol
Christopher McCormack
@cmccormack
Jan 22 16:17
probably them fancy shoes
Jason Luboff
@JLuboff
Jan 22 16:17
Not wearing the shoes lol
Oh well. Going to stay positive for the day!
Christopher McCormack
@cmccormack
Jan 22 16:20
Until you spill your soup all over at lunch
Jason Luboff
@JLuboff
Jan 22 16:21
Shit man! Don't jinx me
Christopher McCormack
@cmccormack
Jan 22 16:26
I will if I want to!
need to make me a little @JLuboff voodoo doll
Jason Luboff
@JLuboff
Jan 22 16:26
Damn man...you're vicious!
Christopher McCormack
@cmccormack
Jan 22 16:27
lol don't worry I'll only use my power for good, and just a little bit of evil
Jason Luboff
@JLuboff
Jan 22 16:28
Surrreee
Christopher McCormack
@cmccormack
Jan 22 16:40
@JLuboff did you have a chance to check out hooks?
Riadh
@KWFE
Jan 22 16:42
hello hello
Christopher McCormack
@cmccormack
Jan 22 16:43
@KWFE hey GM
Jason Luboff
@JLuboff
Jan 22 16:43
@cmccormack No, not yet
Pagnito
@Pagnito
Jan 22 17:08
@cmccormack hey, was it you who shares marko js a while back?
Jason Luboff
@JLuboff
Jan 22 17:08
Ya @cmccormack loves marko
Christopher McCormack
@cmccormack
Jan 22 17:09
Yeah you should all be using it and loving it!
Pagnito
@Pagnito
Jan 22 17:09
haha
Christopher McCormack
@cmccormack
Jan 22 17:09
but don't ask me questions about it because i've never used it
Pagnito
@Pagnito
Jan 22 17:09
i wanna try it out, i was wondering, is it like templates? or react component tpye deal?
lmao
Christopher McCormack
@cmccormack
Jan 22 17:10
I just want to be first on the bandwagon in case it does blow up :D
Pagnito
@Pagnito
Jan 22 17:10
lol
same here
i really like the react component based structure, lookin at docs of marko atm hoping its similar
Christopher McCormack
@cmccormack
Jan 22 17:11
Maybe it's awesome and just needs people like us to nudge it
Pagnito
@Pagnito
Jan 22 17:12
true
hopefully
Tiago Correia
@tiagocorreiaalmeida
Jan 22 17:15
Christopher McCormack
@cmccormack
Jan 22 17:16
it's so cool how they were able to merge those different functions into a single function
Pagnito
@Pagnito
Jan 22 17:44
im determined to build my next project with marko
it seems they have the same thing as react being able to build a bundle, but no native routing support
but there are npm packages for that it seems
Christopher McCormack
@cmccormack
Jan 22 17:48
like React Router?
Pagnito
@Pagnito
Jan 22 17:49
yea
there is two guys there who made references to two diff routers. Though it seems they are both lazy load routers, im not sure tho. Since the bundle is rly small, i wanna b able to use a regular router witthout lazy loading
Christopher McCormack
@cmccormack
Jan 22 17:52
I personally prefer adding my own solutions for stuff like Routing, gives you more flexibility. React is less of a framework than other tools like Vue.
Pagnito
@Pagnito
Jan 22 17:52
how do u make a router?
Christopher McCormack
@cmccormack
Jan 22 17:52
No sorry I just mean I like to be able to use whatever router I want
Pagnito
@Pagnito
Jan 22 17:52
aah
i see
Christopher McCormack
@cmccormack
Jan 22 17:52
but you can make one pretty easy, it's just playing with document.location I believe
Pagnito
@Pagnito
Jan 22 17:53
interesting
Christopher McCormack
@cmccormack
Jan 22 17:53
need to deal with stuff like the back button and not actually submiting GET requests but all should be pretty easy to figure out with the API docs
Pagnito
@Pagnito
Jan 22 17:54
yea ima def look into it more, when i start the project
i think it would be a good learnign exp to build my own
Christopher McCormack
@cmccormack
Jan 22 17:55
It really would be
Pagnito
@Pagnito
Jan 22 17:56
sweet
Kudzu
@czhower
Jan 22 18:18
currently from the home page...
image.png
Guess they fixed it fast.. could repro it from multiple sites but its working again now.
Pagnito
@Pagnito
Jan 22 18:56
anyone know why mongoose framework seems to b lacking updates for a while now? and is there an alternative thats up to date?
Brad
@bradtaniguchi
Jan 22 18:56
@Pagnito Don't use mongoose :P
Pagnito
@Pagnito
Jan 22 18:56
@bradtaniguchi what should i use?
Brad
@bradtaniguchi
Jan 22 18:57
Just mongodb drivers
Pagnito
@Pagnito
Jan 22 18:58
i see
thnx
Brad
@bradtaniguchi
Jan 22 18:58
that's what we do (for better or worse)
Pagnito
@Pagnito
Jan 22 18:58
oof
lol
yea im getting tired of all the deprecation warnings with mongoose
and it seems mongoose requires schemas
Jason Luboff
@JLuboff
Jan 22 18:59
I find vanilla mongo easier to use.... but then again you don't have schemas and what not
Pagnito
@Pagnito
Jan 22 19:00
i personally always like as least amount of abstraction, so im gonna use mongodb.js from now on, tho its a shame everyone teaches mongoose as if mongodb.js doesnt exist
Christopher McCormack
@cmccormack
Jan 22 19:03
mongoose is quite a bit easier to use
and Schemas are a reason to use it
Pagnito
@Pagnito
Jan 22 19:04
true, but i feel like if they never update mongoose anymore, its jus gonna fall out
Christopher McCormack
@cmccormack
Jan 22 19:04
doubt there is much to updated daily, it's not like mongodb is changing drastically every month
Brad
@bradtaniguchi
Jan 22 19:05
Yea, its one of those things that doesn't need to update much.
Pagnito
@Pagnito
Jan 22 19:06
yea, but i feel like everytime i use mongo, i get the same deprecation warnings
Christopher McCormack
@cmccormack
Jan 22 19:06
like what?
Pagnito
@Pagnito
Jan 22 19:06
like dont use findOneAndModify
Christopher McCormack
@cmccormack
Jan 22 19:06
usually when you get those warnings you're supposed to update your code
Pagnito
@Pagnito
Jan 22 19:07
i have to set it in the beginning of file not to use it
and the remove
it seems mongo doesnt have deleteOne and deleteMany anymore, so the remove method doesnt work
Riadh
@KWFE
Jan 22 19:08
how are you doing guys?
Christopher McCormack
@cmccormack
Jan 22 19:08
I don't think I understand the issue, are your concerns with mongoose or mongo driver?
Mongoose is used by many because it's super useful. It's not like it's something different, you can use plain mongo calls as you wish
Pagnito
@Pagnito
Jan 22 19:09
oh wait i might have understood that wrong
i thought that remove called on the deleteOne or deleteMany mongo methods
and i read that those are deprecated in mongo
thus making remove obsolete
Christopher McCormack
@cmccormack
Jan 22 19:12
usually mongoose will update so any changes to mongo are abstracted away if you're using a mongoose method
do mongo driver calls return a promise?
Pagnito
@Pagnito
Jan 22 19:13
i think so, but im not sure, i only used the mongodb methods in shell
Christopher McCormack
@cmccormack
Jan 22 19:15
I've used mongoose quite a bit, and also used the mongo driver a bit - I love what mongoose adds on top and it's not like it gets in your way, it just adds nice functionality
@KWFE good man about to grab some lunch, you?
Pagnito
@Pagnito
Jan 22 19:16
i guess ill have to gain more experience to really know
Brad
@bradtaniguchi
Jan 22 19:17
Always good to make sure you understand the issue before trying to fix it. Its nice to fix stuff real quick, but without knowing whats actually wrong your just shooting in the dark, and you can shoot yourself in the foot :P
Pagnito
@Pagnito
Jan 22 19:18
true
Brad
@bradtaniguchi
Jan 22 19:18
Alright guys, I need some insight on whats the best way to write some db migration code
Christopher McCormack
@cmccormack
Jan 22 19:22
@bradtaniguchi won't be able to help ya there :)
Brad
@bradtaniguchi
Jan 22 19:23
I remember someone talking about running mongo in like "transaction" mode or something so all the writes I do aren't applied,
Jason Luboff
@JLuboff
Jan 22 19:24
Si
I've never used mongo's transaction...but essentially its an all or nothing approach
If one update/insert/delete fails, the whole query fails
And it rolls back any changes made prior to that failure
Christopher McCormack
@cmccormack
Jan 22 19:29
Is it like a grouping of different calls to the db?
Jason Luboff
@JLuboff
Jan 22 19:30
It can be, yes. It could be a single query as well (Maybe a large update for example).
Although... a large update (one thats updating many)...may already be transactional
Jason Luboff
@JLuboff
Jan 22 19:43
Interesting..but makes some sense...mongoose has to convert a lot of things into native driver
Pagnito
@Pagnito
Jan 22 19:44
yea, tho it seemed the most basic/common basic queries perfomed almost the same
Jason Luboff
@JLuboff
Jan 22 19:52
Think I got all my tests created now I can create some TDD
Brad
@bradtaniguchi
Jan 22 19:55
:+1:
Jason Luboff
@JLuboff
Jan 22 19:57
Question is...are my tests good... lol
Brad
@bradtaniguchi
Jan 22 20:33
Now that question is very subjective hehe
alpox
@alpox
Jan 22 20:54
@JLuboff Sry I was out for dinner with my gf - I sent you a response on slack :)
Jason Luboff
@JLuboff
Jan 22 21:22
@bradtaniguchi Aint it though? haha
@alpox No need to ever apologize, I'm the one bugging you (and I replied on Slack as well)
Jeff
@jargonfilter
Jan 22 21:39

hey everyone. So I just started this exercise here: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/spinal-tap-case/
and i just tried a simple regex thing: str.replace(/' '/gi, '-');

it doesn't seem to even change the string at all. shouldnt that at least replace spaces with dashes?

Pagnito
@Pagnito
Jan 22 21:40
anyone does any digital drawing here?
Jeff
@jargonfilter
Jan 22 21:40
oops i actually meant underscores
str.replace(/_/gi, '-');
lol, anyway doesn't seem to do anything
Jason Luboff
@JLuboff
Jan 22 21:41
@jargonfilter What is your full code?
Chris
@crokita
Jan 22 21:42
make sure you assign str.replace to something, as it doesnt modify the original string
Jason Luboff
@JLuboff
Jan 22 21:42
Yup...strings are immutable
Jeff
@jargonfilter
Jan 22 21:42
oh, that would be the problem i guess.
and that was basically all my code since i literally just started the exercise and thought "thats weird" when i console logged it
TIL or maybe I learned it before, forgot it, and learned it again.
Chris
@crokita
Jan 22 21:43
lol. it happens
Jeff
@jargonfilter
Jan 22 21:45
probably happens more with me than it should since I tend to do these exercises in batches then run out of time for a while and then come back to them again and think "so, what is this javascript stuff again?"
Riadh
@KWFE
Jan 22 22:44
hi would anyone tell me what is wrong here?
function isOldEnoughToDrink(age) {
  // your code here    

  if(age => 21){
    return true;
  } else {
    return false;
  }
}
Jason Luboff
@JLuboff
Jan 22 22:45
=
>=
Riadh
@KWFE
Jan 22 22:45
yes i tried that too
Jason Luboff
@JLuboff
Jan 22 22:45
You're creating a function by using =>
What are you supposed to do?
Riadh
@KWFE
Jan 22 22:46
Write a function called "isOldEnoughToDrink".

Given a number, in this case an age, "isOldEnoughToDrink" returns whether a person of this given age is old enough to legally drink in the United States.

Notes:* The legal drinking age in the United States is 21.
Jason Luboff
@JLuboff
Jan 22 22:46
Send me the link please
Brad
@bradtaniguchi
Jan 22 22:46

If you are ever doing something like

"if (/*something*/) {
  return true;
} else {
   return false;
}

Change it to just:

return /*something*/
Jason Luboff
@JLuboff
Jan 22 22:47
Damn it @bradtaniguchi I was going to get to that :P
Brad
@bradtaniguchi
Jan 22 22:47
@KWFE Are you sure you tried >=
Riadh
@KWFE
Jan 22 22:48
yes i did
@JLuboff its on repl.iy
it
Jason Luboff
@JLuboff
Jan 22 22:51
I just tried with your code but using the proper operator (>=) and it passed fine
function isOldEnoughToDrink(age) {
  if ( age >= 21){
    return true;
  }
    else {
      return false;
    }
}
But as Brad said...when you are returning a boolean, you don't need an if/else
Riadh
@KWFE
Jan 22 22:53
try to pass it through repl.iy
it
Jason Luboff
@JLuboff
Jan 22 22:53
....I did.....
Brad
@bradtaniguchi
Jan 22 22:54
the code don't lie
Idk what is even suppose to happen in the repl.it, there are no tests (at least that I can see)
Jason Luboff
@JLuboff
Jan 22 22:56
You have to click the dropdown next to Run and select run tests
Jason Luboff
@JLuboff
Jan 22 23:09
Hmmm... my tests may not be setup right.. argh
Brad
@bradtaniguchi
Jan 22 23:12
Let me see
Yea looks to be passing
Riadh
@KWFE
Jan 22 23:40
@JLuboff but shouldn't it pass the challenge
why it was saying undefined ?
Jason Luboff
@JLuboff
Jan 22 23:40
Do the Run Test. It's showing undefined becuase repl.it kind of sucks.. lol
Brad
@bradtaniguchi
Jan 22 23:53
It says undefined because its acting like the browser console
I assume
so it prints out the whatevers at the end, then undefined (since I assume it uses consoe.log) under the hood
Riadh
@KWFE
Jan 22 23:55
@JLuboff yes it passes the tests but not the challenge anyway i'll just keep learning here on fcc
Brad
@bradtaniguchi
Jan 22 23:55
Yea idk, this code works function isOldEnoughToDrink(age) {return age >= 21;}