These are chat archives for FreeCodeCamp/HelpJavaScript

22nd
May 2018
Ryan Williams
@Ryanwfile
May 22 2018 04:13
For the record collection algorithm I'm trying to delete a property from an object I've tried using delete object[id][prop] , delete object.id.prop, delete object[id].prop and various other combinations as well as assigning the property an undefined value but I can't seem to remove the property from the object, how do I accomplish this? https://codepen.io/Ryanwfile/pen/pLXMGP
Yash Pratap Singh
@kkyashkk
May 22 2018 04:19
Hi
Claudio Restifo
@Marmiz
May 22 2018 04:37

@Ryanwfile

delete collection[id].prop;

prop is also a varaible. You should use the bracket notation for that :)

otherwise it will look for the object key: "prop"
Ryan Williams
@Ryanwfile
May 22 2018 04:38
@Marmiz Thanks I tried that many times, still doesn't work
CamperBot
@camperbot
May 22 2018 04:38
ryanwfile sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1233 | @marmiz |http://www.freecodecamp.org/marmiz
Ryan Williams
@Ryanwfile
May 22 2018 04:38
it just removes the value of that property
Claudio Restifo
@Marmiz
May 22 2018 04:48
@Ryanwfile that's because the rest of the code keeps executing, so you have something down below in the function that keeps a reference to it

just a

delete thing;
return

will do.

anyway, delete is super inefficient. Way more performat to iterate over keys and delete from there.
Also in the second way it's also much easier to return copies of the object, thus keeping an immutable pattern :wink:
Ryan Williams
@Ryanwfile
May 22 2018 04:53
@Marmiz That worked thank you so much
CamperBot
@camperbot
May 22 2018 04:53
ryanwfile sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
api offline
Claudio Restifo
@Marmiz
May 22 2018 05:00
:+1: anytime! Happy coding :sparkles:
Markus Kiili
@Masd925
May 22 2018 05:11
@Marmiz Greetings of proper time of day.
Claudio Restifo
@Marmiz
May 22 2018 05:20
@Masd925 greetings from
"Tue May 22 2018 12:20:45 GMT+0700 (+07)"
anthonygallina1
@anthonygallina1
May 22 2018 05:41
:wave:
I thought I was angry
But no
I am scared any one else feel like that after doing firebase GPO stuff?
Rajat
@rajataudichya
May 22 2018 05:44
@Masd925 Hi
anthonygallina1
@anthonygallina1
May 22 2018 05:44
Did my best now I have to let it go. Any one else go through that? And if so how did you deal with it?
Hi
Markus Kiili
@Masd925
May 22 2018 05:44
@rajataudichya Hi.
anthonygallina1
@anthonygallina1
May 22 2018 05:45
pin drop
Sorry didnt meen to make it go quiet
Markus Kiili
@Masd925
May 22 2018 05:46
@anthonygallina1 It is quiet here usually nowadays.
anthonygallina1
@anthonygallina1
May 22 2018 05:47
@Masd925 thanks :sweat:
CamperBot
@camperbot
May 22 2018 05:47
anthonygallina1 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4800 | @masd925 |http://www.freecodecamp.org/masd925
anthonygallina1
@anthonygallina1
May 22 2018 05:49
Welp guess I am the only one that felt like that. Now I feel extra weird.
I meen besides my normal weird.
Rajat
@rajataudichya
May 22 2018 05:51
@Masd925 Can you help me here?
the search function ain't working and why is wikipedia api so complicated :P
Markus Kiili
@Masd925
May 22 2018 05:53
@rajataudichya I haven't done that project so can't help too much.
Claudio Restifo
@Marmiz
May 22 2018 05:56
@rajataudichya your search request is stalled :)
Claudio Restifo
@Marmiz
May 22 2018 06:04
@rajataudichya if this may help here's an example of a sarch query:
/w/api.php?action=query&format=json&maxlag=2&list=search&srsearch=javascript&srlimit=10
Rajat
@rajataudichya
May 22 2018 06:09
@Marmiz Thanks let me try :)
CamperBot
@camperbot
May 22 2018 06:09
rajataudichya sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1234 | @marmiz |http://www.freecodecamp.org/marmiz
Rajat
@rajataudichya
May 22 2018 06:10
I was trying to generate an api using API Sandbox , how can we generate the URL which you have sent using API Sandbox?
sabahatullah
@sabahatullah
May 22 2018 07:16
could someone help me converting it to jQuery since Edge/IE is not accepting for of Loop
var _spPost = document.querySelector('#sx-res-offerselect-special');
var _posts = document.querySelector('#sx-res-offerselect-all');
const country = ['Australia','USA','Pakistan', 'Turkey','PFAR','XFAR', 'XFMR','XDAR'];
const liElems = document.querySelectorAll(".description__sub");
function searchAndHideLi(elements, countries){
for (const country of countries)
{
for (const ele of elements){
console.log(ele);
if($(ele).closest('li:contains("'+country+'")').length > 0){
console.log(country);
$(ele).closest('li').prependTo('#sx-res-offerselect-special');
return;
}
}
}
}
searchAndHideLi(liElems, country);
李佳超
@oublier720
May 22 2018 09:19
blob
这语句有什么错吗
为什么走不到else
Dhaval Vira
@dhavalveera
May 22 2018 09:20
@oublier720 all Members are not from China or Japan
so post in English only
李佳超
@oublier720
May 22 2018 09:20
sorry,
Is there anything wrong with this statement?
Why can't I go to "else"?
Stephen James
@sjames1958gm
May 22 2018 10:18
@oublier720 if the property is not there then it will be !== "" you need to use
a different way to test that (perhaps hasOwnProperty?)
@sabahatullah for the country array you can use forEach
https://developer.mozilla.org/en-US/docs/Web/API/NodeList
This page shows how to loop over the elements NodeList which is returned from query selector all.
Ramesh
@rnallu
May 22 2018 11:14
Hi guys, I'm using $(selector).append() method for a loop in ajax call. But, when i'm requesting another call thru Click , the result is showing with previous appended data. Already tried e.preventDefault() and cache:false, but invain. Please help. Codepen link. https://codepen.io/anon/pen/qYvMEN
Rajat
@rajataudichya
May 22 2018 11:21
have just finished this challenge
@rnallu you can check my codepen for reference https://codepen.io/rajataudi/pen/gzqyYz
my suggestion would be to console log the json you are getting as if it is an array the dot operator won't work and you will have to use bracket notation
Ramesh
@rnallu
May 22 2018 11:25
@rajataudichya hi, array is working, my problem is with append method cache.
Rajat
@rajataudichya
May 22 2018 11:26
so you mean to say that if you have search twice then the result is appearing twice ? right?
It happened to me as well what I did was I removed all the elements when clicked on submit as you can see in my codepen
@rnallu
Ramesh
@rnallu
May 22 2018 11:29
@rajataudichya exactly, yeah i'm checking your pen.
Rajat
@rajataudichya
May 22 2018 11:29
loved this project but API is totally lame...
Aditya
@ezioda004
May 22 2018 11:30
@rnallu You can do $("#searchResults").empty(); right before $.each()
Ramesh
@rnallu
May 22 2018 11:33
@ezioda004 Yeah, it works, Thanks
CamperBot
@camperbot
May 22 2018 11:33
rnallu sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 563 | @ezioda004 |http://www.freecodecamp.org/ezioda004
Rajat
@rajataudichya
May 22 2018 11:42
anyone here who uses Emmet?
Henry
@GitHub-Henry
May 22 2018 13:58
Norvin Burrus
@ndburrus
May 22 2018 14:05
@rajataudichya this may be helpful: :sparkles:
Dimitris Nik.
@dimitrissnk
May 22 2018 15:00
Hey, check out my code really fast. Can I do that with those switch/case statements or is it wrong? https://codepen.io/dimitris51/pen/jzjaOX?editors=1010
for some reason if I add all that piece of code the page don't want to load
Jason Luboff
@JLuboff
May 22 2018 15:09
@Dimitrios51 Seems to be working for me
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:09
waddup
Jason Luboff
@JLuboff
May 22 2018 15:10
@RoniqueRicketts Hey man
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:10
bruvs and Sis
@JLuboff Wazzup man?
@JLuboff have you used jwt before?
Jason Luboff
@JLuboff
May 22 2018 15:12
Very little
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:12
@JLuboff I am using passport-jwt middleware but for some reason I am unable to grab my token string in the header bruv
Jason Luboff
@JLuboff
May 22 2018 15:13
Shouldn't it be in your session (cookie) not the header?
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:14
@JLuboff I saved it in my local storage.
Jason Luboff
@JLuboff
May 22 2018 15:14
Oh..
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:14
and I am sending it back through the bearer header
Jason Luboff
@JLuboff
May 22 2018 15:15
Gotcha. I've only dealt with using sessions. I tried in the past to use local storage and had a hell of a time
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:15
I am still to learn about them cookies. I heard token are more secure than cookies so that's why I tried it out.
@JLuboff I just saved the token in local storage.
and send it in any request to the server. Without the token you can't hit the backend api
Jason Luboff
@JLuboff
May 22 2018 15:16
And you verified on the front end that the token is in the local storage?
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:16
@JLuboff yes it is
Jason Luboff
@JLuboff
May 22 2018 15:17
And how do you try and access that from the backend?
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:18
@JLuboff you have send the token to access the backend. No token, no access.
Jason Luboff
@JLuboff
May 22 2018 15:18
I get that, but how do you send it/access it from the backend?
Is it part of your url or..?
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:21
@JLuboff I don't access it from the backend. Once my server creates it and send it then its expecting to get it back with every request.
Jason Luboff
@JLuboff
May 22 2018 15:22
@RoniqueRicketts so how does your backend every supposed to know its recieved it if you don't ever access it?
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:23
hmmm. I think I am lost. Are you busy? We could do a session.
Jason Luboff
@JLuboff
May 22 2018 15:24
Beyond chatting on here, ya I am sorry
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:24
slap face! rude
Jason Luboff
@JLuboff
May 22 2018 15:24
:smile: Sorry bud
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:31
Anyways, I have a server that replies to requests. If you provide the correct username and password it generates a token and send it to the client requesting to log in, my client now, stores the token in local storage. My client then sends back the token to the server to get additional data. The server has a middleware that checks to see if the token in present and correct. If it is then the user can get data if not they get an error from the server.
idk if that makes any sense to you.
Jason Luboff
@JLuboff
May 22 2018 15:32
Yes makes sense. However, you're saying your middleware does not get the token (or the token is undefined), right?
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:33
@JLuboff the token is there but for some reason I can't see if to verify the exp date.
Jason Luboff
@JLuboff
May 22 2018 15:34
So you can see the token in your console (on the backend)?
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:35
so if it expire it should return false. I want verify the token on both frontend and backend. Eg on frontend if the token expire then delete it. on the backend if the exp has passed then reject the request.
@JLuboff I am not seeing this but I can access the payload very weird.
Jason Luboff
@JLuboff
May 22 2018 15:37
Hmm.. Ya I'm not too sure then. Seems out of my ballpark
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:38
stop it is is still on your court
This is my file.
Ronique Ricketts
@RoniqueRicketts
May 22 2018 15:44
Have you heard about the chingu.io program?
Jason Luboff
@JLuboff
May 22 2018 15:53
No I haven't
Ronique Ricketts
@RoniqueRicketts
May 22 2018 16:08
damn. it seem like a good little program to do bruv.
Jason Luboff
@JLuboff
May 22 2018 16:16
Looks interesting. Basically they just pair you with others?
Ronique Ricketts
@RoniqueRicketts
May 22 2018 16:41
@JLuboff yes and make things, which is gooood!
Brad
@bradtaniguchi
May 22 2018 18:00
I haven't developed on windows in months, feels funny. Did get cmder, interesting app haha
Jason Luboff
@JLuboff
May 22 2018 18:00
@bradtaniguchi You been working in OS X?
Brad
@bradtaniguchi
May 22 2018 18:01
I work on linux
Jason Luboff
@JLuboff
May 22 2018 18:01
Ah
Brad
@bradtaniguchi
May 22 2018 18:01
Im not rich so I don't have a mac haha
Jason Luboff
@JLuboff
May 22 2018 18:02
They don't provide a computer for you at your work?? Or its running linux?
Brad
@bradtaniguchi
May 22 2018 18:03
Its running linux, and its an old computer, but there's no standards to what I can run so I run manjaro
the only thing I can't figure out is my autoformatting for vscode
Henry
@GitHub-Henry
May 22 2018 18:10
i use eslint for js, and prettier for the rest, but i use windows
Brad
@bradtaniguchi
May 22 2018 18:14

Yea I have prettier being used, but vscode doesn't wrap my html attributes so they look like this:

<my-component [test]="foo" 
                          [otherTest]="bar">

instead they end up like this all the time

<my-component [test]="foo"  [otherTest]="bar">

Its fine for like 2,3 attributes, but I can have like 5 that are long

eh the first one is lined up, idk whats going on there hehe
Henry
@GitHub-Henry
May 22 2018 18:17
i thought that the thing with prettier, it doesn't have a bunch of options and configurations. so, i thought the philosophy with prettier was it will format the code, live with it, and focus on other things
Brad
@bradtaniguchi
May 22 2018 18:18
Yea, but it doesn't seem to be working on my html XD
or something else is
Henry
@GitHub-Henry
May 22 2018 18:23
have you tried playing with the print width option
perhaps lower the number so it doesn't make one long line
sabahatullah
@sabahatullah
May 22 2018 18:50
could someone help me here. I am trying to match the array with the text and based on the moving the Li item into another UL
I have the for of loop (currently commented out) works perfectly. but due to the fact that its not compatible with IE/Edge I need to find an alernative approach with .every function but can't seem to quite get it
Brad
@bradtaniguchi
May 22 2018 18:53
Why not use the old fashioned for loop? or arr.forEach
its supported in IE9
Jason Luboff
@JLuboff
May 22 2018 18:56
Ya... for loops or even for..in loops are supported
Brad
@bradtaniguchi
May 22 2018 18:57
for in !== for of tho
Jason Luboff
@JLuboff
May 22 2018 18:57
And for..of is supported in Edge just not IE
@bradtaniguchi Ya I know. I'm actually not sure the differece between them
sabahatullah
@sabahatullah
May 22 2018 18:58
could you help me converting the for of to any other possible solution.
Jason Luboff
@JLuboff
May 22 2018 18:58
but I know they're different
Brad
@bradtaniguchi
May 22 2018 18:58
1 screws you over and the other one does what you want :P
Jason Luboff
@JLuboff
May 22 2018 18:58
Heh
Brad
@bradtaniguchi
May 22 2018 18:58
I only found this out cuse my editor yelled at me for using for...of basically saying "you sure you want to use this?" and requiring an if statment or something
Jason Luboff
@JLuboff
May 22 2018 19:00
@bradtaniguchi How much do you work with nodejs?
Brad
@bradtaniguchi
May 22 2018 19:01
Not much, I work on our nodejs backend now and then, know some mongodb, and write some utility scripts once in a while
Jason Luboff
@JLuboff
May 22 2018 19:02
Ah.. I was going to ask a best practice question..which you still may or may not know.. so I'll throw it out there
I have several routes that have duplicate or almost duplicate code in seperate code blocks (that is, if /else statement). I want to break out that code into functions. But.. I'm thinking that best practice is to have that in a seperate file that is required and not within the routes file... would you agree?
Brad
@bradtaniguchi
May 22 2018 19:06
Yea definantly move the code out to some reusable block, idk where youd want to put that re-usuable function, maybe in some utils folder or something
Henry
@GitHub-Henry
May 22 2018 19:11
@bradtaniguchi for in returns properties, for of returns values
think of it like, is the property in the object
Jason Luboff
@JLuboff
May 22 2018 19:15
@bradtaniguchi Cool, thanks
CamperBot
@camperbot
May 22 2018 19:15
jluboff sends brownie points to @bradtaniguchi :sparkles: :thumbsup: :sparkles:
:cookie: 486 | @bradtaniguchi |http://www.freecodecamp.org/bradtaniguchi
Brad
@bradtaniguchi
May 22 2018 19:23
yea np, sorry I couldn't be of more help
Jason Luboff
@JLuboff
May 22 2018 20:21
@bradtaniguchi No I think that answered my question fairly well
Henry
@GitHub-Henry
May 22 2018 20:58
@JLuboff might want to look at Norvin's NodeJS Best Practices URLs
Jason Luboff
@JLuboff
May 22 2018 20:59
@GitHub-Henry Neat! Thanks!
CamperBot
@camperbot
May 22 2018 20:59
jluboff sends brownie points to @github-henry :sparkles: :thumbsup: :sparkles:
:cookie: 555 | @github-henry |http://www.freecodecamp.org/github-henry
Henry
@GitHub-Henry
May 22 2018 21:01
np
Keegan
@Keggatron
May 22 2018 23:44
Hi guys, I'm having an issue.
values.bookings.map(booking => {
    axios.put('/api/newbooking',{
        date: values.date,
        booking: [{booked: true}, {booker: values.booker}, {phone:values.phone}]
    });
here I'm trying to get the value from booking to be entered as the key in my model
however when I log that from the backend I get booking rather than the value I would get from the bookings.map function
anyone know how to deal with this?
Moisés Man
@moigithub
May 22 2018 23:57
..im not understandng what u trying to do
Keegan
@Keggatron
May 22 2018 23:58
alright so let's pretend values.booking = ["10:30", "11:00", "11:30"]
I want to update the value I have in my db model for "10:30"