These are chat archives for FreeCodeCamp/HelpJavaScript

24th
Aug 2018
Ross Scarborough
@SourceHorse
Aug 24 2018 02:26
@ezioda004 This won't work if there is a $ in the string.
Ross Scarborough
@SourceHorse
Aug 24 2018 02:32
return str.slice(str.length - target.length) == target ? true : false;
had some trouble with formatting haha
Aditya
@ezioda004
Aug 24 2018 02:47
@SourceHorse Example? Seems to be working with $ in the code (also, its not my code)
Oh I see, yeah it'll be parsed as special character with regexp.
alpox
@alpox
Aug 24 2018 05:13
@Pagnito you should not do api calls in actions unless you use something like redux-thunk or custom middleware. Actions are pure objects, action creators should not contain asynchronous code.
Nitin
@thenm
Aug 24 2018 06:27
I am trying to push element/s from one array to other array. I am unable to do so please help.
let availTickets = [ { ticketid: 343 },{ ticketid: 345 } ];
 let availAgents = [{
          emailAddress: 'fc@fc.com',
          allocatedTicket: ['1']
        },
        {
          emailAddress: 'tl@firstcry.com',
          allocatedTicket: ['2']
        },{
          emailAddress: 'fc1@fc.com',
          allocatedTicket: ['3']
        },
        {
          emailAddress: 'sachin@fc.com',
          allocatedTicket: ['4']
        }];

config.ticketBatch = 1 // Push one 1 ticketId from  availTicket to availAgents allocated tickets

availAgents.forEach((availAgent)=> {
        if(availTickets.length > 0){
          console.log('availAgent', availAgent);
          console.log('Config', config.ticketBatch);
          for(var i = 0; i < config.ticketBatch; i++) {
            if(availTickets[i].ticketid){
              availAgent.allocatedTicket.push(availTickets[i].ticketid);
              console.log('Avail Tickets ID', availTickets[i].ticketid, i);
              availTickets = availTickets.splice(0,config.ticketBatch)
              console.log('availTickets - after delete', availTickets);
            }
          }
        }
      });
Greg Duncan
@GregatGit
Aug 24 2018 08:49
@thenm how did you go?
Nitin
@thenm
Aug 24 2018 08:49
Still no luck trying it.
Greg Duncan
@GregatGit
Aug 24 2018 08:50
@thenm What are you trying to do?
@thenm if it worked - how would avaibleAgents look?
Nitin
@thenm
Aug 24 2018 08:55
Let say availTickets[] are new unassigned tickets which needs to assigned to the availAgent[]. So I need to push the availTickets.ticketid to availAgents.allocatedTicket. And remove the push item from availTickets[].
if config = 1
availAgents = [{
          emailAddress: 'fc@fc.com',
          allocatedTicket: ['1', '343']
        },
        {
          emailAddress: 'tl@firstcry.com',
          allocatedTicket: ['2', '345']
        },{
          emailAddress: 'fc1@fc.com',
          allocatedTicket: ['3']
        },
        {
          emailAddress: 'sachin@fc.com',
          allocatedTicket: ['4']
        }];
if config = 2
availAgents = [{
          emailAddress: 'fc@fc.com',
          allocatedTicket: ['1', '343', '345']
        },
        {
          emailAddress: 'tl@firstcry.com',
          allocatedTicket: ['2']
        },{
          emailAddress: 'fc1@fc.com',
          allocatedTicket: ['3']
        },
        {
          emailAddress: 'sachin@fc.com',
          allocatedTicket: ['4']
        }];
Greg Duncan
@GregatGit
Aug 24 2018 08:58
@thenm I would use your forEach on the availTickets rather than on the availAgents
@thenm Small thing - but when using arrays and objects use const rather than let.
Nitin
@thenm
Aug 24 2018 09:01
@GregatGit How? We need to assign tickets to agent and there could be multiple tickets agent to the single user in one iteration.
Greg Duncan
@GregatGit
Aug 24 2018 09:01
Also because they are numbers, I would keep them as numbers and not strings
Nitin
@thenm
Aug 24 2018 09:02
Actually ticketid is string. These are just dummy values. My mistake
Greg Duncan
@GregatGit
Aug 24 2018 09:07
because this is an array a simple loop would do the trick. Loop over availTickets pushing them into availAgents.allocatedTicket
@thenm why do you have this config.ticketBatch = 1 is it needed?
then why do you have config.ticketBatch = 1 in the loop when it will mean i will only every be 0
Nitin
@thenm
Aug 24 2018 09:10
The number of tickets getting pushed to the availAgents.allocatedTicket depends on that number. config.ticketBatch = 2 then 2 ticket will be pushed
Greg Duncan
@GregatGit
Aug 24 2018 09:11
@thenm but it is used in the forLoop to determine how high i can be
Stephen James
@sjames1958gm
Aug 24 2018 09:12
This
availTickets = availTickets.splice(0,config.ticketBatch)
could be
availTickets.shift()
which just removes the first entry
Greg Duncan
@GregatGit
Aug 24 2018 09:13
config.ticketBatch = availTickets.length
it should be hard coded
Nitin
@thenm
Aug 24 2018 09:13
@GregatGit no it not like that.
Stephen James
@sjames1958gm
Aug 24 2018 09:14
@GregatGit The ticketBatch number determine how many values from availTickets to assign to each agent at a time
Nitin
@thenm
Aug 24 2018 09:14
@sjames1958gm Yes
Greg Duncan
@GregatGit
Aug 24 2018 09:16
@thenm perhaps you should call it that
Nitin
@thenm
Aug 24 2018 10:03
@sjames1958gm and @GregatGit thanks I am able to do atleast assigning the ticket to agent for just single iteration
Bryan Xu
@bryanpalau
Aug 24 2018 11:10

the html does not function@@ some help needed, thanks~

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">
<title>prompt</title>
<script type="text/javascript">
function rec(){
var myname = prompt("enter name", "");
if(myname! = null)
{alert("hello" + myname);}
else
{alert("hello amigo");}

}
</script>
</head>
<body>
<input name = "button" type = "button" onClick = "rec()" value = "write name here"/>

</body>
</html>

catalin560
@catalin560
Aug 24 2018 11:19
@bryanpalau
replace if(myname! = null)
with if (myname !== null)
and read up on conditionals https://www.w3schools.com/js/js_if_else.asp
Zunaid Aslam
@ZunaidAslam
Aug 24 2018 11:30

Can someone explain how does this Regex remove white-space in the front and back.

let hello = " Hello, World! ";
let wsRegex = /^\s*(.*\S)\s*$/; // Change this line|
let result = hello.replace(wsRegex,"$1"); // Change this line

I can understand this part:

/^\s*\s*$/;

but what about this

(.*\S)

The original FCC problem link: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end

Stephen James
@sjames1958gm
Aug 24 2018 11:42
@ZunaidAslam That \S forces middle to match at least one non-space character before the ending \s*
Without that the .* in the middle would match all the way to the end of the string.
Zunaid Aslam
@ZunaidAslam
Aug 24 2018 11:44

@sjames1958gm Still not clear. But I am matching the whitespaces in the front and end to replace. Why do I need to match non-white space in the middle?

Shouldn't it get replaced also that way?

Thank you for replying
tundeiness
@tundeiness
Aug 24 2018 11:45
guys I need help with this
function updateRecords(id, prop, value) {
         //collection[album][prop]
         for(let album in collection){
        if( prop !== "tracks" && value !== ""){
          collection[album][prop] = value;
         }
        if(prop === "tracks" && !(collection[album].hasOwnProperty(prop))){
            collection[album][prop] = [value];
        }

        if(prop === "tracks" && value !== "" ){
          collection[album][prop].push(value);
        }

        if(collection[album][prop] ==="" ){
          delete collection[album][prop];
        }

     }

 return collection;
}
only two is not passing
Stephen James
@sjames1958gm
Aug 24 2018 11:51
@ZunaidAslam Because regex matching is greedy, if you don't have \S to mark the end of the middle part it will consume to the end.
Basically it is saying consume all characters up until the last \S then you can match the \s to the end.
Aditya
@ezioda004
Aug 24 2018 11:51
@ZunaidAslam The regex is matching the whole string, its just that (.*\S) is matching and remembering (capturing) the non-whitespace part, and you're replacing the whole string with this captured part.
Stephen James
@sjames1958gm
Aug 24 2018 11:51
/^\s*(.*)\s*$/; with this there is nothing to stop the middle .* from consuming all the way to the end of the string.
@tundeiness You should probably use else if each case is exclusive.
Looks like after it does collection[album][prop] = [value]; then the next if will also add value to the array
tundeiness
@tundeiness
Aug 24 2018 12:00
@sjames1958gm not working...
Bryan Xu
@bryanpalau
Aug 24 2018 12:08
@catalin560 thanks for the suggestion!
Stephen James
@sjames1958gm
Aug 24 2018 12:12
@tundeiness What do you have now?
tundeiness
@tundeiness
Aug 24 2018 12:13
@sjames1958gm
function updateRecords(id, prop, value) {
         //collection[album][prop]
         for(let album in collection){
        if( prop !== "tracks" && value !== ""){
          collection[album][prop] = value;
         }

         if(prop === "tracks" && !(collection[album].hasOwnProperty(prop))){
            collection[album][prop] = [value];
        }

        if(prop === "tracks" && value !== "" ){
          collection[album][prop].push(value);
        }else{
          delete collection[album][prop];
        }


     }

 return collection;
}
@sjames1958gm I think the challenge is knowing what the task is asking. sometime the pseudo code refers to "value" and "prop" literally...getting to know where to apply them is the issue
Stephen James
@sjames1958gm
Aug 24 2018 12:37
@tundeiness
You should be using else if
if () {
}
else if() {
}
else if() {
}
else {
}
This code will change the collection and then the next if will also change the collection (if you don't use else if)
         if(prop === "tracks" && !(collection[album].hasOwnProperty(prop))){
            collection[album][prop] = [value];
        }
tundeiness
@tundeiness
Aug 24 2018 12:42
@sjames1958gm yeah I get the idea of using that approach. I have used it recently and I had to start all over again.
Jason Luboff
@JLuboff
Aug 24 2018 15:14
Morning
Christopher McCormack
@cmccormack
Aug 24 2018 15:21
Hi @JLuboff :wave: gm
Jason Luboff
@JLuboff
Aug 24 2018 15:24
what up
Christopher McCormack
@cmccormack
Aug 24 2018 15:26
training!
We have to do like 15 different training things every year and our team is due end of the month, trying to knock them out
not fun stuff either, like anti-money laundering, anti-corruption, etc...
Jason Luboff
@JLuboff
Aug 24 2018 15:27
Ugh training
Christopher McCormack
@cmccormack
Aug 24 2018 15:27
stuff my team never really deals with but the whole org has to do
Jason Luboff
@JLuboff
Aug 24 2018 15:27
Ya I have to do I think its OSHA training stuff monthly
Christopher McCormack
@cmccormack
Aug 24 2018 15:28
that's funny we don't have to do that one
eww monthly
Jason Luboff
@JLuboff
Aug 24 2018 15:29
Ya...I don't actually do it monthyl...maybe every 3 months I'll catch up
Christopher McCormack
@cmccormack
Aug 24 2018 15:30
OSHA? More like OSHIt I need to do my training I'm three months behind on!
... I'll go now
Jason Luboff
@JLuboff
Aug 24 2018 15:31
...
:joy:
Man...I breesed through the Flexbox stuff...but..I'm still struggling to put together something that works...essentially I want to create a row, and then be able to have columns within that...playing with it in codepen right now but.. eh..
Henry
@GitHub-Henry
Aug 24 2018 15:54
flexbox and grid the one two punch of css
Jason Luboff
@JLuboff
Aug 24 2018 15:56
Do I need to use grid in combo with flexbox?
Actually think I just figured out what I needed with just flexbox
Christopher McCormack
@cmccormack
Aug 24 2018 16:13
@JLuboff you're probably just going to have to keep nesting flexbox
that's the only odd part about it to me, you have a flex item that is also a flex parent
Jason Luboff
@JLuboff
Aug 24 2018 16:13
@cmccormack Ya... thats what I'm finding but it gets a bit confusing or things just don't work how I'm expecting heh
Henry
@GitHub-Henry
Aug 24 2018 16:13
flex box is more for rows or columns, grid is more for page design
Christopher McCormack
@cmccormack
Aug 24 2018 16:14
@JLuboff http://meetuptonight.mackville.net/ if you want to see the CSS I used for my "cards" it's all flexbox and I am pretty proud of it :)
Henry
@GitHub-Henry
Aug 24 2018 16:15
@cmccormack nice work
Christopher McCormack
@cmccormack
Aug 24 2018 16:15
The buttons change direction a few times based on media queries
@GitHub-Henry thanks :)
I used JSS though so it may have confusing nonsensical classnames
Jason Luboff
@JLuboff
Aug 24 2018 16:17
I may just have to pick your brain a bit @cmccormack ;)
Christopher McCormack
@cmccormack
Aug 24 2018 16:17
Please do it will force me to remember how I did any of it haha
Jason Luboff
@JLuboff
Aug 24 2018 16:17
haha
Christopher McCormack
@cmccormack
Aug 24 2018 16:17
Havent done much in the last few weeks and I feel like I've already forgotten much
alpox
@alpox
Aug 24 2018 16:19
@JLuboff you can have what you said easily with only one flex parent
flex-flow: row wrap;
In case you didnt find it yet :)
Although if you have more of a table design with fixed width columns you are probably better off with grid
Christopher McCormack
@cmccormack
Aug 24 2018 16:21
how would his columns work then? I am assuming the columns would also contain children and be flex-direction: column correct @JLuboff ?
Jason Luboff
@JLuboff
Aug 24 2018 16:21
Ya... this is what I have right now https://codepen.io/jluboff/pen/vzLBEe
So...its doing what I want currently..but.. not sure I'm actually putting everything correct here
Gah I hate CSS... :joy:
Christopher McCormack
@cmccormack
Aug 24 2018 16:22
oh so when you say column you mean more like a framework column
a percentage of a row
or am I wrong again? haha
Jason Luboff
@JLuboff
Aug 24 2018 16:23
Ya. I guess I'm trying to emulate bootstrap / bulma's method of grids but using flexbox
So..one thing I'm unsure of...do I need display: flex; for all my children?
Christopher McCormack
@cmccormack
Aug 24 2018 16:26
only if you want the children to be flex positioned I believe
@JLuboff I think you can set the flex grow to a different integer to have it take up more or less space, instead of using percentages
but I forget
Jason Luboff
@JLuboff
Aug 24 2018 16:27
Ya... thats true (about flex-grow)
Actually, I think just flex is what I'd want
Christopher McCormack
@cmccormack
Aug 24 2018 16:32
flex is short for flex-grow, flex-shrink, and flex-basis
I was just referring to the first, however you implement
Jason Luboff
@JLuboff
Aug 24 2018 16:33
ah ya good call
Christopher McCormack
@cmccormack
Aug 24 2018 16:33
I think I read it's best to use flex so it can better calculate
Jason Luboff
@JLuboff
Aug 24 2018 16:44
Good to know
Jason Luboff
@JLuboff
Aug 24 2018 18:18
:turtle:
Christopher McCormack
@cmccormack
Aug 24 2018 18:25
:rabbit2:
Jason Luboff
@JLuboff
Aug 24 2018 18:25
Who shall win?
Christopher McCormack
@cmccormack
Aug 24 2018 18:48
:monkey: probably
Jason Luboff
@JLuboff
Aug 24 2018 18:48
Where did the monkey come from?
Late entrant?
Christopher McCormack
@cmccormack
Aug 24 2018 18:50
he was pulling the strings the whole time
Jason Luboff
@JLuboff
Aug 24 2018 18:51
Suprise attack?
Christopher McCormack
@cmccormack
Aug 24 2018 18:53
haha :poop:
Jason Luboff
@JLuboff
Aug 24 2018 18:58
@cmccormack still working on your training?
Christopher McCormack
@cmccormack
Aug 24 2018 18:58
Just finished, now watching some AWS videos
which I guess is just more training haha
Jason Luboff
@JLuboff
Aug 24 2018 18:59
Cool cool
Christopher McCormack
@cmccormack
Aug 24 2018 19:04
What you up to? Still flexin?
Jason Luboff
@JLuboff
Aug 24 2018 19:05
Finished that. Got it to do what I wanted. I'm not using it anywhere near its capacity
Have another form that I'm going to apply it to though
And otherwise..eating lunch before heading to the gym
Christopher McCormack
@cmccormack
Aug 24 2018 19:06
Same eating some ribs I smoked last night, best lunch ever
Jason Luboff
@JLuboff
Aug 24 2018 19:06
Might work on stupid proofing our conference room signs.. (after lunch)
Christopher McCormack
@cmccormack
Aug 24 2018 19:06
Yeah flexbox doesn't really take all that much for most usage
@JLuboff stupid proof is impossible
Jason Luboff
@JLuboff
Aug 24 2018 19:07
Touche
I never said completely stupid proof though :joy:
Christopher McCormack
@cmccormack
Aug 24 2018 19:08
haha
Jason Luboff
@JLuboff
Aug 24 2018 19:09
Nah... a while ago I made it so they could input meetings for any date, or add to the day (prior, they could only do the day of and if they needed to change, they had to reinput all meetings)
So when they input meetings, it makes sure those meetings don't overlap, but it doesn't check prior meetings. I need to fix that.
Christopher McCormack
@cmccormack
Aug 24 2018 19:20
yeah you do
so you made that whole system?
Jason Luboff
@JLuboff
Aug 24 2018 19:33
Ya, was originally just two pages, one for inputting meetings and one to display on the sign. Used php to write to a json file. Now they can input/edit/delete meetings and everything is written to a mongo database
Oh and hosted via node instead of iis
Christopher McCormack
@cmccormack
Aug 24 2018 19:54
look at you man super admin!
sounds like fun projects
Jason Luboff
@JLuboff
Aug 24 2018 19:55
That’s Systems Developer to you!
But ya it is fun except when shit doesn’t work for some reason lol
Christopher McCormack
@cmccormack
Aug 24 2018 19:57
I thought that was the fun part, solving problems!
Jason Luboff
@JLuboff
Aug 24 2018 20:17
...sometimes...sometimes noit'
Jason Luboff
@JLuboff
Aug 24 2018 20:26
I really need to get in the habit of checking my web pages in all browsers.
Christopher McCormack
@cmccormack
Aug 24 2018 20:28
nah
only check in latest chrome
Jason Luboff
@JLuboff
Aug 24 2018 20:28
That'd still bite me in the ass ;)
Jason Luboff
@JLuboff
Aug 24 2018 20:44
I'm starting to get a bit more control over flex..
Christopher McCormack
@cmccormack
Aug 24 2018 20:54
@JLuboff hah it was a joke
so you're becoming more... flex-ible?
Jason Luboff
@JLuboff
Aug 24 2018 20:55
Just a tad
Pagnito
@Pagnito
Aug 24 2018 22:36
@alpox yea im usin thunk
cant rerender my component for the life of me
oh no wait i know why now
Jason Luboff
@JLuboff
Aug 24 2018 22:44
I bet @alpox is sleeping...that or partying
Pagnito
@Pagnito
Aug 24 2018 22:50
i want to call out two actions from one component