These are chat archives for FreeCodeCamp/HelpJavaScript

23rd
Jan 2019
Pagnito
@Pagnito
Jan 23 00:09
anyone familiar with the aggregate in mongo
?
Brad
@bradtaniguchi
Jan 23 00:10
Yup
like 2/3rds of our app runs on that haha
Pagnito
@Pagnito
Jan 23 00:12
what does it help me with, i cant seem to understand from the complex examples in the docs
lets say i want to get two records that have age property, and i want to get the oldest and youngest person out of all the records, can i do that with aggregate?
Brad
@bradtaniguchi
Jan 23 00:13
You can basically do anything in the aggregate. But in your use-case you probably could do that without the aggregate (maybe)'
Jason Luboff
@JLuboff
Jan 23 00:14
aggregates are fun!
Brad
@bradtaniguchi
Jan 23 00:14
The main idea behind the aggregate is you can "chain" operations like find, unwind, project, etc.
Jason Luboff
@JLuboff
Jan 23 00:14
As well as breaking documents up by certain criteria
Pagnito
@Pagnito
Jan 23 00:14
oof, i havent heard of unwind or project yet T.T
Brad
@bradtaniguchi
Jan 23 00:14
Yea, like I said you can do pretty much anything
Pagnito
@Pagnito
Jan 23 00:15
yea breaking documents up is what i need
i need to break it down to two records
Jason Luboff
@JLuboff
Jan 23 00:15
unwind is what you'll need to break documents up
And project is just the fields you want to return
Pagnito
@Pagnito
Jan 23 00:16
ooh thats niiice
tho i gues i was wrong, its not quite wat i need >.<
Jason Luboff
@JLuboff
Jan 23 00:17
Here's an aggregate I used for the Stock Chart App...
db.collection('symbol').aggregate([
                    { $unwind: '$stockData' },
                    {
                        $match: {
                            datePulled: moment().format('MM-DD-YYYY'),
                            stockData: {
                                $gte: req.params.timeLength,
                                $lte: moment().format('YYYY-MM-DD')
                            }
                        }
                    },
                    { $project: { _id: 1, symbol: 1, stockData: 1, color: 1 } },
                    {
                        $group: {
                            _id: '$_id',
                            symbol: { $push: '$symbol' },
                            color: { $push: '$color' },
                            stockData: { $push: '$stockData' }
                        }
                    },
                    {
                        $project: {
                            symbol: { $arrayElemAt: ['$symbol', 0] },
                            stockData: 1,
                            color: { $arrayElemAt: ['$color', 0] }
                        }
                    }
]
If I remember correctly... $stockData is an array in each document
so by unwinding on that, I'm getting a seperate document for each element in stockData
Pagnito
@Pagnito
Jan 23 00:18
what does group do?
Jason Luboff
@JLuboff
Jan 23 00:19
Groups together documents based on some criteria. So here I'm regrouping my unwound documents
Pagnito
@Pagnito
Jan 23 00:20
damn bro i got alot to learn lol
Jason Luboff
@JLuboff
Jan 23 00:20
It was a lot of trial and error heh
Pagnito
@Pagnito
Jan 23 00:20
hehe
i belive that
Jason Luboff
@JLuboff
Jan 23 00:21
I would write it out in mongo shell then once it did what I wanted, move it into my app
Pagnito
@Pagnito
Jan 23 00:23
seems painful to write in shell
so i found this solution
but the guy on overflow says i need the _id property in $group
Jason Luboff
@JLuboff
Jan 23 00:24
Yes, _id is mandatory in $group
Pagnito
@Pagnito
Jan 23 00:25
hold on ima remove it and see what happens to better understand
i dont get it, why does it need it even its null
Pagnito
@Pagnito
Jan 23 00:28
k
Pagnito
@Pagnito
Jan 23 00:34
a bit dissapointed in my boi stephen grider, the complete mongo course and he isnt teaching me aggregate :*(
Jason Luboff
@JLuboff
Jan 23 00:34
M101JS goes over it, or atleast use to
Pagnito
@Pagnito
Jan 23 00:36
it seems that course is retired
i think ima take another one from maximillian on udemy
that guy is on point, looked over his syllabus, looks pretty legit >:)
Jason Luboff
@JLuboff
Jan 23 00:38
oh thats too bad it was a good course
Pagnito
@Pagnito
Jan 23 00:39
it said it was because trends move really fast, and they want to keep things updated, so they will proly have another one soon if not already, i should proly check that O.o
Pagnito
@Pagnito
Jan 23 01:17
cant undestand y im gettin this
Artist.estimatedDocumentCount() is not a function
doing exact same thing in a differnt file with no problem
BlogPosts.estimatedDocumentCount()
Brad
@bradtaniguchi
Jan 23 01:23
Artists? (with an s)
Pagnito
@Pagnito
Jan 23 01:26
nah, its the teachers code, so he used Artist
i think in this project there was a different version of mongoose and count() seems to work
man what a headache lol
Chinmay Joshi
@dienigma
Jan 23 04:56
Hello guys
I tried solving this challenge
Basic Algorithm Scripting: Truncate a String
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.
function truncateString(str, num) {
  if (str.length <= num) {
    return str;
  } else {
    return str.slice(0, num > 3 ? num - 3 : num) + '...';
  }
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);
So here is the problem with this. The truncateString() function does not work in two cases
first one is the one in the code itself "A- tisket ...."
Second one it is not working for right now is "Peter Piper picked a peck of pickled peppers", 11
Works for other cases.
But not working for these two
abraham anak agung
@padunk
Jan 23 05:33
@dienigma have you solved it? why do you need 3 ?
Chinmay Joshi
@dienigma
Jan 23 06:04
Yes I solved it
So in the else condition I just had to return str.slice(0,num)
and then add a '...'
alexV
@alexpande
Jan 23 09:52
hello

<script>
var arr=[
{s:'A1',t:'B1'},
{s:'A1',t:'B2'},
{s:'B1',t:'C1'},
{s:'B1',t:'C2'}
]
console.log(arr)

var arr1=[['A1'],['B1','B2'],['C1','C2']]
console.log(arr1)
</script>
How can I convert arr to arr1?

How to write a conversion method´╝č
Blauelf
@Blauelf
Jan 23 11:49
Is there any specification what those s and t (and the pair of both) mean?
alexV
@alexpande
Jan 23 14:32
s
s
s means source, t means target.
Riadh
@KWFE
Jan 23 15:56
hey
Christopher McCormack
@cmccormack
Jan 23 15:58
@KWFE hello
Riadh
@KWFE
Jan 23 15:58
@cmccormack how are you today.?
Christopher McCormack
@cmccormack
Jan 23 15:59
Good, just jumping into my projects. You?
Jason Luboff
@JLuboff
Jan 23 16:03
Morning
Riadh
@KWFE
Jan 23 16:03
i'll jump into fcc js section lol
@JLuboff GM
Jason Luboff
@JLuboff
Jan 23 16:04
Whats happening?
Riadh
@KWFE
Jan 23 16:04
who can do me a favor i want to get a video link from a webpage
youtube video
when i try to watch it inside the website it says playback problem
Christopher McCormack
@cmccormack
Jan 23 16:07
I think they deleted it, if you copy the ID of the video to youtube itself it shows it doesn't exist for me
Jason Luboff
@JLuboff
Jan 23 16:08
@cmccormack What up
Christopher McCormack
@cmccormack
Jan 23 16:09
@JLuboff oh nm man you?
Learning about Google Cloud today
Riadh
@KWFE
Jan 23 16:09
what is the id @cmccormack
Jason Luboff
@JLuboff
Jan 23 16:09
Neat! I'm...not learning about Google Cloud.. lol
I am going to work on passing my TDD though!
Christopher McCormack
@cmccormack
Jan 23 16:09
v2daYloSpakQbQaO I think
Riadh
@KWFE
Jan 23 16:11
for me it generated another ID
Christopher McCormack
@cmccormack
Jan 23 16:12
oh then I'm not sure, maybe view source
Riadh
@KWFE
Jan 23 16:13
i did this is why i am asking here if you know any good tricks to get the link
Christopher McCormack
@cmccormack
Jan 23 16:58
@JLuboff sounds like fun man let me know any neat tricks you learn
Jason Luboff
@JLuboff
Jan 23 16:58
Testing is neat!
You should do it!
I already fixed my code for my initial TDD...and I wrote another TDD and already have the code accomadating that now
So.. I'm actually working things out quicker then I would otherwise I believe
Christopher McCormack
@cmccormack
Jan 23 17:09
I do do it :) just haven't done it much
some mocha/chai on the FCC projects, using jest and supertest on my current
Jason Luboff
@JLuboff
Jan 23 17:13
I'm using Jest and supertest as well. Not really all that much with the supertest though. Just making sure I get back the proper status is returned along with checking some of the data
Jason Luboff
@JLuboff
Jan 23 17:25
@cmccormack Have you done any Jest snapshot testing for React?
Christopher McCormack
@cmccormack
Jan 23 17:25
Nope not until I start working on the frontend, still just starting the backend stuff, very lazy lol
is it nice?
Jason Luboff
@JLuboff
Jan 23 17:26
I've only created one test to try it out. I'll have to look into it more to determine what the real purpose is ... lol
Christopher McCormack
@cmccormack
Jan 23 17:44
There are some really cool React testing tools, some that will load your component on its own to test, without having to load the whole app
I guess if React is Javascript you can do that anyway, but I think these tools do stuff with props to let you play with the component in the browser or something like that
Jason Luboff
@JLuboff
Jan 23 17:45
Thats the idea between the snapshots. The first time you run the test, it takes a snapshot and then if you make any changes I guess it would catch it
Christopher McCormack
@cmccormack
Jan 23 17:59
that's just visual?
Jason Luboff
@JLuboff
Jan 23 18:00
I haven't looked enough into it to be able to answer that
Brad
@bradtaniguchi
Jan 23 18:22
Yea I've heard of those, I think those are for screenshot tests, so "visual"tests. Never used one tho, but sounds interesting haha
Christopher McCormack
@cmccormack
Jan 23 18:24
that would definitely be useful for some of my components, like my Form components that do a lot of padding/margin stuff
Jason Luboff
@JLuboff
Jan 23 18:30
Yes!
enestatli
@enestatli
Jan 23 18:37
Hello, whats up
Jason Luboff
@JLuboff
Jan 23 18:38
Just working away...yourself?
Christopher McCormack
@cmccormack
Jan 23 18:40
@enestatli heya
enestatli
@enestatli
Jan 23 18:41
I am trying to build a Product Landing Page
I have scrapped 16,000+ cars dataset and I do not know what to do right now :D
Jason Luboff
@JLuboff
Jan 23 18:43
Thats a lot of cars
Christopher McCormack
@cmccormack
Jan 23 18:43
you mean scraped?
why do you need that much data? the landing page isn't really all that complicated
enestatli
@enestatli
Jan 23 18:45
*scraped :)
@cmccormack dataset is just to test myself
Christopher McCormack
@cmccormack
Jan 23 18:46
you just need a simple product page. mine passes all the tests and doesn't have close to 16,000 items in a dataset :)
enestatli
@enestatli
Jan 23 18:46
but I want to do something with it :D
Christopher McCormack
@cmccormack
Jan 23 18:46
ok build a fullstack app that lets you display details and filter the data by different properties
enestatli
@enestatli
Jan 23 18:47
@cmccormack that's look cool! I can get something from your css
@cmccormack that's nice idea! do I need a server to store dataset?
Jason Luboff
@JLuboff
Jan 23 18:48
a fullstack app means you're creating front and back ends
enestatli
@enestatli
Jan 23 18:48
@JLuboff the filter process is gonna be my backend I guess
Christopher McCormack
@cmccormack
Jan 23 18:48
@enestatli you don't technically need your own server, you can use tools like glitch.com to host the backend, possibly frontend as well, and store your database on a free cloud service like mlab
enestatli
@enestatli
Jan 23 18:49
@cmccormack never heard of them before, I will take a look, thank you!
Christopher McCormack
@cmccormack
Jan 23 18:49
might be better to go through the FCC backend stuff first though
I made that sound easy but there are a lot of steps
but it would be a great project to start on and learn while you go
devs tend to do better learning when they have something they are passionate to work on but don't know what to do at each step learning that way can be more valuable as you actually solved a problem you had
enestatli
@enestatli
Jan 23 18:51
@cmccormack that's what I thought, firstly finishes the JS&Data projects
Christopher McCormack
@cmccormack
Jan 23 18:52
it certainly doesn't hurt to at least get some theoretical knowledge, helps build a better foundation
Pagnito
@Pagnito
Jan 23 19:14
hey anyone know how to enable backspace to go back in chrome without extension?
or make shift backspace better
nvm i found the vimium shift h
Christopher McCormack
@cmccormack
Jan 23 19:25
@Pagnito you like that browser extension?
Pagnito
@Pagnito
Jan 23 19:25
i dnno, i just started using it to just try it out
do u use it?
Christopher McCormack
@cmccormack
Jan 23 19:37
nope
Brad
@bradtaniguchi
Jan 23 20:58
alt+backarrow for the win
Pagnito
@Pagnito
Jan 23 20:59
why do so many instroctors make they create user end point as /users and not /users/create or /createUser ?
Brad
@bradtaniguchi
Jan 23 20:59
odds are there will only be 1 POST request at /users why be more verbose than neccessary?
Pagnito
@Pagnito
Jan 23 21:00
i suppose but it seems to make more sense to me, /users would make sense as get a list of users
Chris
@crokita
Jan 23 21:02
it's because they follow REST API conventions: https://www.restapitutorial.com/lessons/httpmethods.html
artze
@artze
Jan 23 21:03
@Pagnito Hi, if I can cihme in. There is really no right or wrong in terms of how you name API endpoints. But it is accepted as a standard to follow REST naming methodologies to keep things standardized as much as possible. That way consumers of your API endpoints will be able to understand what it does more quickly.
@crokita you beat me to it!
Pagnito
@Pagnito
Jan 23 21:04
@artze @crokita i see, that makes sense, i shall have to bow down to it, as i believe in use of standards
Chris
@crokita
Jan 23 21:04
ahaha. your input is still good, @artze
artze
@artze
Jan 23 21:05
If you want an even more in depth guideline description, this can be helpful too: https://docs.microsoft.com/en-us/azure/architecture/best-practices/api-design
Jason Luboff
@JLuboff
Jan 23 21:09
@crokita @artze Thanks. I'm going to take a look at both of those sites. I didn't know there was a standard convention lol
Chris
@crokita
Jan 23 21:09
oh, lol. no problem
Amit Patel
@AmitP88
Jan 23 21:11
hey guys, has anyone here used react native? I'm trying to open my first project on my android phone using expo, but I keep running into timeout network errors. I've tried various solutions but nothings worked so far.
artze
@artze
Jan 23 21:15
no experience with React Native, mate. sorry
Amit Patel
@AmitP88
Jan 23 21:18
no worries, thanks anyways