These are chat archives for FreeCodeCamp/HelpJavaScript

12th
Apr 2018
Christopher McCormack
@cmccormack
Apr 12 2018 00:33
If anyone is interested Kent C. Dodds is going to talk to a ReactJS Meetup in Phoenix in about 1.5 hours - https://www.youtube.com/watch?v=Jlj8mVaDrb4
jusgoose
@gusd773
Apr 12 2018 03:42
can anybody tell me how to get my button trio centered?
blob
*{
    margin:0;
    padding:0;
    font-family: arial;
}

#header {
    margin: auto;
    padding: 0;
    width: 100%;
    background-color: grey;
    height: 100px; 
}
#logo {    
    float: left;
}
#logo img {
    width: 200px;
    height: 100px;
}

#header ul{
    margin: 10px;
    width: 500px;
    float: right;
    padding:10px;
    border: 2px solid black;

}
#header li {
    position: relative;
    padding: 5px;
    border: 1px solid white;
    display: inline-block;
}
blob
jusgoose
@gusd773
Apr 12 2018 04:00
no? ok cool lol
ArchivalBoat50
@ArchivalBoat50
Apr 12 2018 04:06
Hey guys, I'm making a function that checks for a palindrome and this code is a little test run. So my str variable is "race car" and my palindrome variable would return "race car", however my x variable returns "rac ecar: which is confusing because I don't know how it could return that. Thus this is giving my function an error.
str = "race car";
var palindrome = str.replace(/[W_]+/g, "");
x = str.toLowerCase().replace(/[W_]+/g, "").split("").reverse().join("");
if (x == palindrome) {
  console.log("True");
}

else {
  console.log("False");
 }



console.log(palindrome);
console.log(x);
sorry i meant my x variable returns "rac ecar"
Aditya
@ezioda004
Apr 12 2018 04:14
@ArchivalBoat50 Is your regex suppose to be that? If you want to select non-alpha then you have to make it /[\W_]+/
ArchivalBoat50
@ArchivalBoat50
Apr 12 2018 04:17
@ezioda004 Oh what is the difference between those two? I'm also still getting the same problem
Aditya
@ezioda004
Apr 12 2018 04:19
@ArchivalBoat50 [W] just selects the letter "W", I'm assuming you want to use special character W which matches any non-word character
So you have to use \ before using that character.
ArchivalBoat50
@ArchivalBoat50
Apr 12 2018 04:22
@ezioda004 Oh whoops! I forgot about the \
@ezioda004 Seems like it's working now. Do you know why x returned "rac ecar" at first? I can't really seem to trace it. Thanks btw
CamperBot
@camperbot
Apr 12 2018 04:22
archivalboat50 sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 532 | @ezioda004 |http://www.freecodecamp.org/ezioda004
Aditya
@ezioda004
Apr 12 2018 04:25
@ArchivalBoat50 Because /[W_]+/g isnt matching the whitespace and therefore doesnt do anything in this case so you're just reversing race car ==> rac ecar
https://regex101.com/ is a good place to check what your regex is matching.
ArchivalBoat50
@ArchivalBoat50
Apr 12 2018 04:31
@ezioda004 Ah I see, thanks for your help!
CamperBot
@camperbot
Apr 12 2018 04:31
archivalboat50 sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
api offline
Henry
@GitHub-Henry
Apr 12 2018 06:13
@gusd773 seek ye the ways of the green frog and answers ye shall find
lemonfiled
@lemonfiled
Apr 12 2018 06:41
var myStr = "<a href='http://www.example.com' target='_blank'>Link</a>"; What is wrong with that?
kirbyedy
@kirbyedy
Apr 12 2018 06:57
You should have two single quotes ' and four double quotes "
says in the challenge
lemonfiled
@lemonfiled
Apr 12 2018 07:01
@kirbyedy Where do the other double quotes write?
kirbyedy
@kirbyedy
Apr 12 2018 07:01
well I think if you reverse the quotes you will pass the challenge
So start with a single and all in between doubles...
end with a single of course :)
lemonfiled
@lemonfiled
Apr 12 2018 07:06
@kirbyedy My English is not well,So,Can you write the correct results?
kirbyedy
@kirbyedy
Apr 12 2018 07:08
well writing the correct result is not helping its doing the challenge instead of you ;)
your solution is almost correct, just reverse the quotes you have, instead of this " start with this '
and change the rest
lemonfiled
@lemonfiled
Apr 12 2018 07:12
@kirbyedy The correct result is this var myStr = '<a href="http://www.example.com" target="_blank">Link</a>'; Thanks for your help
CamperBot
@camperbot
Apr 12 2018 07:12
lemonfiled sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star2: 2147 | @kirbyedy |http://www.freecodecamp.org/kirbyedy
kirbyedy
@kirbyedy
Apr 12 2018 07:24
:thumbsup:
Alex
@alexandrupintilei
Apr 12 2018 07:44
image.png
whatever here shouldn be 100?
Aditya
@ezioda004
Apr 12 2018 07:57
@alexandrupintilei Seems correct. .filter() returns a filtered array, so in this case. There's only 1 element in tasks so it checks the condition task.id > 1 which returns true and therefore it pushes the whole object (element) to the new array.
Alex
@alexandrupintilei
Apr 12 2018 10:02
@ezioda004 thx
CamperBot
@camperbot
Apr 12 2018 10:02
alexandrupintilei sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 534 | @ezioda004 |http://www.freecodecamp.org/ezioda004
Alex
@alexandrupintilei
Apr 12 2018 10:02
Any ideea how i cant get value .name here?
image.png
Stephen James
@sjames1958gm
Apr 12 2018 10:05
@alexandrupintilei illegal return sounds like you have a return statement that is not inside a function
Alex
@alexandrupintilei
Apr 12 2018 10:06
@sjames1958gm hi, i solve it
was a type mistake
Stephen James
@sjames1958gm
Apr 12 2018 10:07
@alexandrupintilei :+1:
JunTian
@vpertj
Apr 12 2018 10:32

function myTest(val) {
var answer = "";
// 请把你的代码写在这条注释以下
var a,b,c;
switch(val){

  case a:
 answer="apple";
  break;
  case b:
  answer="bird";
  break;
  case c:
  answer="cat";
  break;
default:
  answer="stuff";

}

// 请把你的代码写在这条注释以上
return answer;
}

// 你可以修改这一行来测试你的代码
myTest(a);

function myTest(val) {
var answer = "";
// 请把你的代码写在这条注释以下
var a,b,c;
switch(val){

  case a:
 answer="apple";
  break;
  case b:
  answer="bird";
  break;
  case c:
  answer="cat";
  break;
default:
  answer="stuff";

}

// 请把你的代码写在这条注释以上
return answer;
}

// 你可以修改这一行来测试你的代码
myTest(a);

ReferenceError:a is not defined
ReferenceError:a is not defined
ReferenceError:a is not defined
Norvin Burrus
@ndburrus
Apr 12 2018 10:34
@vpertj which lesson is this?
JunTian
@vpertj
Apr 12 2018 10:34
Adding a default option in Switch statements
@ndburrus Adding a default option in Switch statements
@ndburrus 204
@ndburrus lesson 204
@ndburrus lesson name is Adding a default option in Switch statements
May Kittens Devour Your Soul
@diomed
Apr 12 2018 10:39
u dont have to mention him in every line in the same minute
JunTian
@vpertj
Apr 12 2018 10:39
@diomed ok
Norvin Burrus
@ndburrus
Apr 12 2018 10:42
@vpertj notes... :sparkles:
  • this line: var a,b,c; should be removed
  • the cases (a-c) require parentheses (seeinstructions example/format)
JunTian
@vpertj
Apr 12 2018 10:48
@ndburrus Still the same
Stephen James
@sjames1958gm
Apr 12 2018 10:58
@vpertj Your case a: should be case "a": and same for others.
Also, myTest("a");
Charlie Taylor
@chazmcgrill
Apr 12 2018 11:06
You want to be testing the val parameter rather than declaring empty variables.
Danny Chan
@chandanny
Apr 12 2018 12:00
hello
Charlie Taylor
@chazmcgrill
Apr 12 2018 12:48
@chandanny hello
Danny Chan
@chandanny
Apr 12 2018 13:27
@chazmcgrill hi
Francois Beyers
@Blusoup
Apr 12 2018 13:28
@Blusoup
can anyone help me please. I'm trying to write a cookie to check if the customer is logged in or out. Basically I want to write an if statement to check for the logout button and then console.log of the customer is logged in or logged out.
var logOffButton = $(".prersonal-actions-login").length; if(logOffButton !== 1) { // If logged out // console log "logged out" here } // Then you set cookie to current status } else { // If logged in // console log "logged in" here } // Then you set cookie to current status }
can someone please advise how I would do that?
Edwin Moses
@3dw1nM0535
Apr 12 2018 13:45
I just started a repo for algorithm solutions for developers by developers. You are a developer through other developers. Please checkout the repo and add your interesting algorithm solution you ever encountered during your code lifecycle and interviews.
https://github.com/3dw1nM0535/ubuntu.git. Please reach out if you find any issues in the repo.
Nate Mallison
@NJM8
Apr 12 2018 14:24
Has anyone here read YDKJS?
I was reading up and going, chapter 2 yesterday and he says there is no strict inequality comparison
but there is, maybe I misunderstood?
From the book: "What about coercion? Similar rules as == comparison (though not exactly identical!) apply to the inequality operators. Notably, there are no "strict inequality" operators that would disallow coercion the same way === "strict equality" does."
'42' != 42 // false
'42' !== 42 // true
Simorel
@SimoralX
Apr 12 2018 15:05
I use code like: "replace(/\W/g, '')", but I can't replace character "_". Is there someone know why? Thanks!
Jason Luboff
@JLuboff
Apr 12 2018 15:14
@SimoralX \W does not match _ so you need to include it in either a character set /[\W_]/g or using the OR operator /\W|_/g (you may have to test those, but I think my syntax is correct)
Simorel
@SimoralX
Apr 12 2018 15:14
@SimoralX I know why, It's my fault;Sorry, Thanks.
CamperBot
@camperbot
Apr 12 2018 15:14
sorry simoralx, you can't send brownie points to yourself! :sparkles: :sparkles:
Simorel
@SimoralX
Apr 12 2018 15:15
@JLuboff Thanks
hoangtvcc
@hoangtvcc
Apr 12 2018 16:13
..
Ian
@toianw
Apr 12 2018 17:16
@NJM8 In that section, by 'inequality operators", Kyle is referring to these operators (<, >, <=, >=) .
Brad
@bradtaniguchi
Apr 12 2018 17:46
Nothing like the smell of a whole bunch of bugs (20+) over the night
Jason Luboff
@JLuboff
Apr 12 2018 17:47
@bradtaniguchi What'd you do, smash them?
Brad
@bradtaniguchi
Apr 12 2018 18:02
First I need to ask for more details in all of them since they hare basically "did this, this broke" -_-
Jason Luboff
@JLuboff
Apr 12 2018 18:03
Hehe
Nate Mallison
@NJM8
Apr 12 2018 18:33
@toianw thanks for the clarification, I figured I was missing something
CamperBot
@camperbot
Apr 12 2018 18:33
njm8 sends brownie points to @toianw :sparkles: :thumbsup: :sparkles:
:cookie: 515 | @toianw |http://www.freecodecamp.org/toianw
Nate Mallison
@NJM8
Apr 12 2018 18:33
Anyone here good with npm?
I got a message from github that one of my dependencies was out of date and is vulnerable to attack.
but it's not my dependency, it's a packages dependency, so do I have to get the package creator to update or can I do it?
Nate Mallison
@NJM8
Apr 12 2018 18:41
Another one, I found the file github is telling me is vulnerable, I cannot tell what dependency installed it as my package lock is 1000 lines long. but I noticed several other packages depend on the questionable package, but they are using the lastest version. so does npm install install several copies of the same version? I assume no, will it install both versions? probably yes?
Charlie Taylor
@chazmcgrill
Apr 12 2018 18:47
site which helps you find out why a package is vulnerable = https://snyk.io/
usually package just needs updating
Nate Mallison
@NJM8
Apr 12 2018 18:53
How can you tell what package is installing another package?
They are all up to date via npm update and ncu
Nate Mallison
@NJM8
Apr 12 2018 18:59
man, this package stuff feels a little senseless to me sometimes
i checked out the package, it's literally 30 lines of JS, it's ms, for converting a given time to milliseconds
I see packages in there for flattening arrays, converting to camelcase, converting back from camelcase, checking if something is camelcase? why go through all the trouble to install these packages when you can write all that in < 100 lines. I don't get it
or even just copy their code
Nate Mallison
@NJM8
Apr 12 2018 19:12
snyk didn't find the vulnerability, interesting, me this code is just for learning anyways. it isn't in production anywhere
Christopher McCormack
@cmccormack
Apr 12 2018 19:34
@NJM8 why do you think writing 100 lines of code is easier than a few lines of import code?
Plus the idea is not to have to copy paste your code around in lots of projects but instead to push them to npm for reuse later. Many people pushed these for their own use
And you have a single place of record to keep it up to date
Nate Mallison
@NJM8
Apr 12 2018 19:37
@cmccormack because it's not like deciding to write my own linked list versus the native linked list, it's my own linked list versus yours. Which means I place my trust in you to write a good linked list that fits my needs
Christopher McCormack
@cmccormack
Apr 12 2018 19:37
That's why there are star ratings and why they are open source so you can contribute.
And I would trust some of those much more than your own because they actually tested it and tried to make it compatable in all sorts of scenarios that we may not even consider
look at lodash for example
sure you could write your own but so many have contributed to make those small functions better what's the advantage?
And again, many of those are personal projects that they also shared, you don't have to use it
Imagine you write a better one and share it, but now there are people like you that wouldn't use it because they didn't write it themselves
Nate Mallison
@NJM8
Apr 12 2018 19:41
sure, but I would still be relying on your implementation and all that you included. my problem with the package mentality is I have this issue github is telling me about and all available utilities to update it say it's updated, so somewhere there is a cyclical dependency or something that isn't working correctly. this wouldn't happen if people just rolled their own solutions
Christopher McCormack
@cmccormack
Apr 12 2018 19:41
You would never get any work done if you had to write your own solutions for everything
Nate Mallison
@NJM8
Apr 12 2018 19:42
and I totally agree but imho there is a threshold, something like lodash, mongoose, databases, yes I'll use the public code. but flattening arrays and converting time to ms? come on
Christopher McCormack
@cmccormack
Apr 12 2018 19:42
These packages are usually actively maintained if you read the github issues pages, often when a dependency is out of date it gets brought up as an issue and soon remedied
Nate Mallison
@NJM8
Apr 12 2018 19:42
are you a programmer or a package installer
Christopher McCormack
@cmccormack
Apr 12 2018 19:42
Again, those were probably people just sharing their own solution
you don't have to use them
The answer is 'Yes'
Nate Mallison
@NJM8
Apr 12 2018 19:44
it's just a different mentality
Christopher McCormack
@cmccormack
Apr 12 2018 19:44
You can write your own code all you want, and for a long time that's going to be a great way to improve your skills, but at some point you don't want to write the same function for the 90th time and you push it
Nate Mallison
@NJM8
Apr 12 2018 19:44
right, that's why I have my own stuff I've written and I reuse that. haha
Christopher McCormack
@cmccormack
Apr 12 2018 19:44
it's not really, it's just a beginner vs advanced mentality
Nate Mallison
@NJM8
Apr 12 2018 19:45
also an opinion
Christopher McCormack
@cmccormack
Apr 12 2018 19:45
OK
Nate Mallison
@NJM8
Apr 12 2018 19:47
as a web developer you live in the package world, are you going to drop in a linked list from the web while writing C for an embedded device with no internet connection?
I still can't figure out where this package is coming from, it says it's from debug -> stylus but I have a hard time believing they have an out of date package
Christopher McCormack
@cmccormack
Apr 12 2018 19:48
Are you asking me? I don't consider myself a web developer and I have written C and C++ and Java and Python and written many of my own packages - and every one of these languages has wonderful package libraries written by experts and refined over time to be better than most things an individual would write
Nate Mallison
@NJM8
Apr 12 2018 19:50
hmm, stylus version is on the latest version but my installed sub dependencies are not
At the end of the day I hear you, but I have a DDOS vulnerability in my app because someone decided not to write 30 lines of JS to convert any time to MS. So I don't stand impressed.
Christopher McCormack
@cmccormack
Apr 12 2018 19:52
did you npm i?
Nate Mallison
@NJM8
Apr 12 2018 19:52
rm and i
Christopher McCormack
@cmccormack
Apr 12 2018 19:53
@NJM8 yup that's a risk when you use outside dependencies
Nate Mallison
@NJM8
Apr 12 2018 19:54
that's all I'm saying, when I know how to do something I'll do it my way rather than rely on someone else, then the risk is on me. when you rely on other people you rely on who they rely on as well. your giving your security 2-3-4 hands away.
I also installed npm-check-updates and it says I'm good.
Jason Luboff
@JLuboff
Apr 12 2018 19:55
Personally I like using packages... literally makes everything easier for me! (so long as I understand the Docs lol)
Nate Mallison
@NJM8
Apr 12 2018 19:56
ah, maybe it's because I'm using an old version of express, which is specified by expressworks
Christopher McCormack
@cmccormack
Apr 12 2018 19:56

Here's a list of most of my packages just for the node side of my project:

const express = require('express')
const cors = require('cors')
const path = require('path')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const passport = require('passport')
const session = require('express-session')
const MongoStore = require('connect-mongo')(session)
const logger = require('morgan')

If I had to write any single one of these it would probably put me back at least 6 months

see how I have 0 linked list packages
well, maybe path would be easy enough to replicate
but path is battle hardened while mine would be just enough to make it work
Nate Mallison
@NJM8
Apr 12 2018 19:58
will old versions of packages update their dependencies?
Christopher McCormack
@cmccormack
Apr 12 2018 19:59
like the same version?
I don't think so
Nate Mallison
@NJM8
Apr 12 2018 19:59
nah man you can write all of that in like, two days, zero vulnerabilities
Jason Luboff
@JLuboff
Apr 12 2018 19:59
path is a built in node module too so you aren't really installing anything extra
Christopher McCormack
@cmccormack
Apr 12 2018 19:59
haha if I I copy the source code
Nate Mallison
@NJM8
Apr 12 2018 19:59
let's do it.
Christopher McCormack
@cmccormack
Apr 12 2018 20:01
@NJM8 I guess what I'm getting at is there is a convenience vs security trade-off, and over time you'll find the right balance.
Jason Luboff
@JLuboff
Apr 12 2018 20:02
Why do you think that a non-professional (no offense @cmccormack ) can rewrite a tried and true module in that short of a period with no vulnerabilities? The only reason would be that it would be written to do exactly what is needed at the time and nothing else..?
Brad
@bradtaniguchi
Apr 12 2018 20:02
I mean if you do it yourself you could still create the same, or more security vulernabilities too
Christopher McCormack
@cmccormack
Apr 12 2018 20:02
@JLuboff I think that was sarcasm :joy:
Jason Luboff
@JLuboff
Apr 12 2018 20:02
Ah... damn! Should have added /s then :P
Nate Mallison
@NJM8
Apr 12 2018 20:02
yea like if I have express 3.0 and debug gets updated, is anyone updating debug on 3.0? probably not. but the express version for expressworks is 4.11.2.... oh nvm I am on the lastest. wth
@cmccormack I agree, what I'm saying is I'll never ever install a package for flattening arrays, besides the fact that it's less than ten lines, there can be assumptions about how you flatten them that can actually drastically affect performance.
so when it comes to things like that I think it's better to be a programmer not a package installer and understand the problem at hand.
Christopher McCormack
@cmccormack
Apr 12 2018 20:05
I can almost guarantee you that lodash will do a better faster job than you could at flattening arrays
Nate Mallison
@NJM8
Apr 12 2018 20:07
you sure about that? Is it optimized for deeply nested arrays or long sets of arrays? you don't get both
Christopher McCormack
@cmccormack
Apr 12 2018 20:07
Uh sure you can
Nate Mallison
@NJM8
Apr 12 2018 20:08
and how to you know ahead of time if breadth first or depth first will be more efficient?
Brad
@bradtaniguchi
Apr 12 2018 20:08
didnt the guy that made lodash's key features end up doing implimentations for firefox or something?
Jason Luboff
@JLuboff
Apr 12 2018 20:09
wouldn't that be two different functions? (I've only used lodash minimally)
Brad
@bradtaniguchi
Apr 12 2018 20:09
aren't they the same if you need to flatten everything?
Christopher McCormack
@cmccormack
Apr 12 2018 20:10
And if you (the programmer) knows whcih to use then you also know which lodash implementation to use if you wanted
Assuming it's a single level deep you'd probably use _.flatten
And I'm sure someone has solved the problem somewhere, even if it isn't lodash. it's what geeks love to do :)
Nate Mallison
@NJM8
Apr 12 2018 20:13
does lodash have one implementation or many?
I was assuming one
Christopher McCormack
@cmccormack
Apr 12 2018 20:13
has _.flatten and _.flattenDeep I believe
Christopher McCormack
@cmccormack
Apr 12 2018 20:19
I might spend the rest of the day reading all their source :)
Jason Luboff
@JLuboff
Apr 12 2018 20:23
Nerd
Christopher McCormack
@cmccormack
Apr 12 2018 20:24
@JLuboff or anyone else - know why this might not work?
module.exports = mongoose => {
  ...
  // This works
  const Poll = mongoose.model('Poll', PollSchema, 'polls')
  return Poll

  // this doesn't
  // return mongoose.model('Poll', PollSchema, 'polls')
}
Jason Luboff
@JLuboff
Apr 12 2018 20:25
Probably becuase its mongoose :P
What happens if you return the one that doesnt work?
Christopher McCormack
@cmccormack
Apr 12 2018 20:25
I think it might have something to do with how exports are wrapped, but I do NOT have this issue with my Users model
ReferenceError: Poll is not defined
not sure where yet though
Christopher McCormack
@cmccormack
Apr 12 2018 20:39
oh! I think it was because of hoisting - I was using Poll.find({}) in the same export so I had to create Poll as a variable. XD
Jason Luboff
@JLuboff
Apr 12 2018 20:47
@cmccormack Sorry got stuck with something, but... was Poll.find({}) returning anything?
Christopher McCormack
@cmccormack
Apr 12 2018 20:47
The issue was Poll didn't exist locally when I removed the variable and just returned the result of the model call
Now I'm trying to find out how I can do it without explicitly creating Poll within the same function
I have a little pre function in there to check if it already exists by a simliar name https://github.com/cmccormack/voting-app/blob/master/models/poll.js if curious
Jason Luboff
@JLuboff
Apr 12 2018 20:51
Not sure that I follow, but thats probably to do with the fact that I don't know much about mongoose
Christopher McCormack
@cmccormack
Apr 12 2018 20:53
There is an event chain that happens around saving and other actions you can take advantage of to run code
but yeah, me neither. I found some things I liked in the documentation and used them but not 100% certain how it all actually works
Jason Luboff
@JLuboff
Apr 12 2018 20:55
@cmccormack How does it know what Poll is (in regards to the find)? Is it that you're defining it in the function call mongoose.model('Poll'...?
Christopher McCormack
@cmccormack
Apr 12 2018 20:56
it's at the bottom, presumably hoisted
const Poll = mongoose.model('Poll', PollSchema, 'polls')
anthonygallina1
@anthonygallina1
Apr 12 2018 20:57
Hi :)
Christopher McCormack
@cmccormack
Apr 12 2018 20:57
@anthonygallina1 hi
@JLuboff mongoose is weird man
Jason Luboff
@JLuboff
Apr 12 2018 21:00
@cmccormack Ok got it. That was kind of confusing me. Essentially you're defining it there I guess. I dunno.
I get that the ORM style of Mongoose is prefered over just vanilla mongo....but ugh..
I'd rather just stick with vanilla lol
Christopher McCormack
@cmccormack
Apr 12 2018 21:01
Yeah creating it at the bottom, it's hoisted and can be used when the exported function is actually called
I think
@JLuboff once you try it you'll forget how to do vanilla
Jason Luboff
@JLuboff
Apr 12 2018 21:02
I :heart: vanilla, I can't turn my back on it!
Christopher McCormack
@cmccormack
Apr 12 2018 21:02
so nice to just chain stuff like
    Poll.find()
      .populate('createdBy')
      .exec((err, polls) => {
        if (err) {
          return next( Error('Error retrieving polls from database') )
        }
 //...
Jason Luboff
@JLuboff
Apr 12 2018 21:05
Whats that doing? Finding all polls, populating a field?
Christopher McCormack
@cmccormack
Apr 12 2018 21:05
I like this one even better
      Poll
      .where({
        'shortName': params.poll,
        'choices.choice': selectedChoice,
      })
      .update({ $inc: { 'choices.$.votes': 1 } })
      .exec((err) => { ... })
Jason Luboff
@JLuboff
Apr 12 2018 21:06
That one is just a findOneAndUpdate
Christopher McCormack
@cmccormack
Apr 12 2018 21:06
yeah it will populate a field if it uses something like mongoose.Schema.Types.ObjectId as the type
yeah but I like the readability of mine better :)
Jason Luboff
@JLuboff
Apr 12 2018 21:07
Psh
findOneAndUpdate is easy to read!
Christopher McCormack
@cmccormack
Apr 12 2018 21:14
@JLuboff mongoose has that too but the idea of chaining is pretty nice - there are better examples http://mongoosejs.com/docs/queries.html
anthonygallina1
@anthonygallina1
Apr 12 2018 21:15
@JLuboff :)
Christopher McCormack
@cmccormack
Apr 12 2018 21:15
again it's more convenience than anything else
I very much like chaining methods :)
Jason Luboff
@JLuboff
Apr 12 2018 21:15
Fair enough. To each their own :D
anthonygallina1
@anthonygallina1
Apr 12 2018 21:18
I am waiting for this to come in the mail. http://shop.oreilly.com/product/0636920028031.do
Just one of the ones I want in hard copy on my desk
Jason Luboff
@JLuboff
Apr 12 2018 21:24
@anthonygallina1 Cool, have you done the M101JS course offered by Mongo University?
anthonygallina1
@anthonygallina1
Apr 12 2018 21:24
@JLuboff The node one I did
Made a mongo sstore
Final proj
Jason Luboff
@JLuboff
Apr 12 2018 21:25
Yup, thats the one
anthonygallina1
@anthonygallina1
Apr 12 2018 21:26
Man I dont think I am all that and a bag of chips
But they ssaid I was in top 10%
Is a good feeling
Jason Luboff
@JLuboff
Apr 12 2018 21:27
Haha, you should feel good about that
anthonygallina1
@anthonygallina1
Apr 12 2018 21:28
well validition helps to feel better about time expenditure
yes
Jason Luboff
@JLuboff
Apr 12 2018 21:28
I agree