These are chat archives for FreeCodeCamp/HelpJavaScript

23rd
Feb 2018
FlashHero
@FlashHero
Feb 23 03:14
@alpox @bradtaniguchi now I understand thanks
CamperBot
@camperbot
Feb 23 03:14
flashhero sends brownie points to @alpox and @bradtaniguchi :sparkles: :thumbsup: :sparkles:
:star2: 1547 | @alpox |http://www.freecodecamp.org/alpox
:cookie: 390 | @bradtaniguchi |http://www.freecodecamp.org/bradtaniguchi
May Kittens Devour Your Soul
@diomed
Feb 23 10:20
:four_leaf_clover:
FlashHero
@FlashHero
Feb 23 12:19
Is there any reasons why <script src='filepath'></script> wouldn't work it points to the right reactjs file but cannot read jsx html elements even with babal-loader in webpack
alpox
@alpox
Feb 23 12:39
@FlashHero Because that refers to a whole script and the script would not go through webpack and therefore, babel-loader would also not do its work
@FlashHero Webpack takes all your js files (which are somehow dependencies of your entrypoint) And puts them into a bundle. That bundle is which you can add as <script>
So webpack does the step of packing up all your files into one - while pushing it through a compilation pipeline in which also babel does its work
You can therefore not use an arbitrary jsx file with a script tag
@FlashHero To correct myself a little bit, you CAN use jsx scripts with a script tag - but not with webpack/babel-loader, but with including babel also as a script: <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
And then use type="text/babel" on the script tag:
<script type="text/babel" src="filepath"></script>
But i would advise against using babel-standalone like this as it pulls in too many dependencies into the browser
Nate Mallison
@NJM8
Feb 23 12:59
hey I have a question about Jasmine. I'm using to test in the command line but I want to see the test results when they pass and not just the green dot. How can I set up the console reporter?
I've read some stuff on SO and see that jasmine comes with a console reporter I'm just not sure how to set it up
alpox
@alpox
Feb 23 13:17
@NJM8 You can create either a Custom Reporter or use a predefined reporter from a Node Module. They have a TerminalReporter in there which you can configure.
Chris
@ConnectCodes
Feb 23 13:37

Hi guys, I’m stuck in "Pairwise challenge” “Given an array arr, find element pairs whose sum equal the second argument arg and return the sum of their indices.”

I dont know how to make reduce check every element agaist the other elements in arrwithout using a for loop. I checked agaist one value if(val + 4 == arg)which returns 3 splice(index,1) and indices += index; which sent the index to var = indeces.

If I use for loop to check every element like val + [i] == arg it gets really messy specially when I remove the paired value arr.splice(index,1) Every post on reduce uses sum example which isn't helpful. I feel I am not using reduce ’s parameters `(acc, val)’ properly.
https://codepen.io/Codeconnect/pen/paLxvr

Stephen James
@sjames1958gm
Feb 23 13:47
@ConnectCodes consider you are looking for arg - val in the remainder of the array you could use indexOf(index+1) to search the rest of the array
Rather than splicing place a null value into the array when you use the value
@ConnectCodes If you are using reduce, you need some sort of loop or iterator to find the match - indexOf - can encapsulate this loop
Chris
@ConnectCodes
Feb 23 13:54
@sjames1958gm I see it makes sense, I will try that, thank you
CamperBot
@camperbot
Feb 23 13:54
connectcodes sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 9019 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
FlashHero
@FlashHero
Feb 23 14:25
@alpox ok thanks
CamperBot
@camperbot
Feb 23 14:25
flashhero sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1549 | @alpox |http://www.freecodecamp.org/alpox
Chris
@ConnectCodes
Feb 23 14:42

@sjames1958gm little confused I thought I got it but now I am scratching my head. Is indexof searching for val in arr?

var reducer = arr.reduce((acc, val, index) => {
        // val + 4 == arg
        if(arg - val == arr[arr.indexOf(index+1)]) {
            console.log("acc:", acc, "val:", val, "index:", index);
            return indices += index;
        }
        return acc;
    });

    return "sum " +  indices;

https://codepen.io/Codeconnect/pen/paLxvr

Kietil
@Kietil
Feb 23 14:47
is it possible to get codeblocks like this with syntax color, with just html/css/js? I use html's <pre> tag , but they are difficult to read with only 1 color.
Nate Mallison
@NJM8
Feb 23 14:52
@alpox Thanks, I was looking at some of those tools. Is there a way to set it up globally so that if I run jasmine myFile.spec.js in the terminal it will print out the passing test results? I don't want to configure it for each spec file.
CamperBot
@camperbot
Feb 23 14:52
njm8 sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1550 | @alpox |http://www.freecodecamp.org/alpox
abraham anak agung
@padunk
Feb 23 15:20
@ConnectCodes why you search for this arr[arr.indexOf(index+1)]? I think you looking for arg-val
alpox
@alpox
Feb 23 15:55
@NJM8 I would also have to investigate. I never used jasmine. I only used jest until now :D
Daniel Romero
@Ranacode
Feb 23 15:59
Rookie question, how can I find for specific files inside a path ?
like this:
node_modules/bootstrap/dist/js/*.js
alpox
@alpox
Feb 23 15:59
@NJM8 As far as i see, jasmine does not have a test runner which might be the main problem. You may want to use Karma for that which is the suggested and most often used one for jasmine
Daniel Romero
@Ranacode
Feb 23 15:59
but instead of all the files that end on js, the only ones that I want
alpox
@alpox
Feb 23 16:06
@Ranacode ls node_modules/bootstrap/dist/js | grep -P "what.*+you.*+want.js$"
There goes a regex
Tom
@moT01
Feb 23 16:12
margin: 10px; would it be safe to call 10px a parameter?
alpox
@alpox
Feb 23 16:18
@moT01 Hmm it may not be save, but it may be valid
:D
Tom
@moT01
Feb 23 16:22
any better suggestions
here's the sentence
.container {
display: grid;
grid-template-columns: 50px 50px;
}
"Note that the number of parameters given to the grid-template-columns property
 indicates the number of columns in the grid, and the value of each parameter
 indicates the width of each column.",
alpox
@alpox
Feb 23 16:24
Hmm I'd say the 10px is a value which is given as a parameter :D
I think that text says it in a good way
the value of each parameter 10px would be the value
Or here 50px
Tom
@moT01
Feb 23 16:25
i think value is maybe better - but then i would be saying the value of each value
yea, i think its good enough like that
@alpox thanks
CamperBot
@camperbot
Feb 23 16:26
mot01 sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1551 | @alpox |http://www.freecodecamp.org/alpox
Dimitris Nik.
@dimitrissnk
Feb 23 16:26
What's up guys, I would like to know, is it possible to get the length of a specific argument that the user will input in a function?
Aditya
@ezioda004
Feb 23 16:26
@Dimitrios51 Use rest parameter?
Tom
@moT01
Feb 23 16:27
not sure that link is right
you want the length of one of the arguments - not the number of arguments
Dimitris Nik.
@dimitrissnk
Feb 23 16:28
@ezioda004 I haven't done that yet...
Basically, this is what I want http://prntscr.com/iisn4f But I am getting a typerror, target.length is not a function
Aditya
@ezioda004
Feb 23 16:30
length is a property, not a method.
Dimitris Nik.
@dimitrissnk
Feb 23 16:31
@ezioda004 so I can't get the length of the target string that the user will enter with the length() ? :/
abraham anak agung
@padunk
Feb 23 16:32
@Dimitrios51 target.length without ()
Aditya
@ezioda004
Feb 23 16:32
^ lengthis always a property
abraham anak agung
@padunk
Feb 23 16:37

Hi all, i still confused with scoping.

function wrapEl (a) {
  var result = [];

  for (var i = 0, n = a.length; i < n; i++) {
    result[i] = () => a[i];
  }
  return result;
}

var wrapped = wrapEl([10,20,30,40,50]);
var f = wrapped[0];
f();

So why it returned undefined?

Markus Kiili
@Masd925
Feb 23 16:46
@padunk i is a.length after the loop has run out, so a[i] will return undefined.
abraham anak agung
@padunk
Feb 23 16:49
@Masd925 but in for loops, i < n, but did it ignore it and goes to i++?
Aditya
@ezioda004
Feb 23 16:50
@Masd925 Correct me if I'm wrong, this is because of closure right? result access the value of i at the time its being executed?
alpox
@alpox
Feb 23 16:56
@ezioda004 Exactly.
And i is a.length at the time of the execution of the closure because the variable is defined as var i which declares i in functionscope and not in local blockscope. This means that there is only one value of i at a time for one call of wrapEl.
If you use let instead of var the variable i gets created in the local block scope of the for loop and the i is preserved for each of its iteration (block)
Aditya
@ezioda004
Feb 23 16:59
@alpox Yeah that's what I thought too, thanks
CamperBot
@camperbot
Feb 23 16:59
ezioda004 sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1552 | @alpox |http://www.freecodecamp.org/alpox
abraham anak agung
@padunk
Feb 23 17:02
@alpox so it is better use let in for loops?
Aditya
@ezioda004
Feb 23 17:07
@padunk Its better yes, you can also use IIFEs to resolve this issue though.
Jason Luboff
@JLuboff
Feb 23 17:12
Morning
Sweet Coding :)
@SweetCodingInc
Feb 23 17:14
@padunk
function wrapEl (a) {
  var result = [];

  for (var i = 0, n = a.length; i < n; i++) {
    result[i] = ((e) => () => e)(a[i]);
  }
  return result;
}

var wrapped = wrapEl([10,20,30,40,50]);
var f = wrapped[0];
console.log(f()); // 10
abraham anak agung
@padunk
Feb 23 17:15
@alpox @ezioda004 yes, thanks.
CamperBot
@camperbot
Feb 23 17:15
padunk sends brownie points to @alpox and @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 473 | @ezioda004 |http://www.freecodecamp.org/ezioda004
:star2: 1553 | @alpox |http://www.freecodecamp.org/alpox
abraham anak agung
@padunk
Feb 23 17:16
@SweetCodingInc never saw an arrow IIFE, nice.
Markus Kiili
@Masd925
Feb 23 18:21
@JLuboff Yo.
Jason Luboff
@JLuboff
Feb 23 18:27
@Masd925 Whats up?
Markus Kiili
@Masd925
Feb 23 18:29
@JLuboff I did a 2min55s breath hold with empty lungs this week. That was refreshing. What fun have you been doing this week.
Jason Luboff
@JLuboff
Feb 23 18:30
@Masd925 Nice! Mmm.. Just been working on a work project (essentially a request application which needs to send out freqent emails, etc. ) and looking like I'll be moving in a few weeks so..gotta start packing I guess
Brad
@bradtaniguchi
Feb 23 18:34
@JLuboff Can I ask how your sending out the emails? I'm curious :D
Jason Luboff
@JLuboff
Feb 23 18:36
@bradtaniguchi Ya I'm building the backend with NodeJS so I'm using nodeMailer module. Sending through our internal smtp server.
Its all internal otherwise, I'd consider using our email provider (Office 365) smtp
...It's going to be a stupid amount of emails though. First when a request is put in, an email will go to ~7 individuals. Then there is the approval process which requires approval from (currently) 5 individuals. Every time they go in and make a change (whether they're saying yes or no or adding a comment) they want an email going out to all the approvers. So at minmum thats 5 emails if everyone says Yes or No. But then if you have a mix..and people changing there minds.. ugh.
Brad
@bradtaniguchi
Feb 23 18:40
@JLuboff Yea that sounds like a lot of emails going out haha, how come you didn't use office 365 to provide the emails?
Jason Luboff
@JLuboff
Feb 23 18:41
Eh.. already have an smtp server relay setup in house...don't need authentication for it lol Also a bit of laziness... I'd have to go search out the required info (I'm an admin for O365 but..still..laziness)
Brad
@bradtaniguchi
Feb 23 18:42
Ah I see haah
Jason Luboff
@JLuboff
Feb 23 18:42
I guess partly just going along with the current setup of things as well. Thats how our other in house apps deal with email relay (I didn't design/build those)
Kaz Baig
@kbaig
Feb 23 18:46
What up @JLuboff
Jason Luboff
@JLuboff
Feb 23 18:47
@kbaig Just staying busy..you?
Kaz Baig
@kbaig
Feb 23 18:48
@JLuboff trying to work to distract myself from the idea that I might have fried my PC last night
A new power supply should come in by the morning so we'll see if anything is fried
Jason Luboff
@JLuboff
Feb 23 18:49
@kbaig Why do you think you fried it? Won't power on?
Kaz Baig
@kbaig
Feb 23 18:50
PMing
Brad
@bradtaniguchi
Feb 23 18:51
I see, yea once there's a precedent how you do stuff changes. Thanks for the info @JLuboff, I only know of 1 way to send emails and was wondering how other people do it haha
CamperBot
@camperbot
Feb 23 18:51
bradtaniguchi sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2343 | @jluboff |http://www.freecodecamp.org/jluboff
Jason Luboff
@JLuboff
Feb 23 18:52
@bradtaniguchi :+1: I have some forms on our intranet page that uses PHP.. it's disgusting. :D
Markus Kiili
@Masd925
Feb 23 18:52
:imp:
Brad
@bradtaniguchi
Feb 23 18:55
haha, PHP is not for me XD
Jason Luboff
@JLuboff
Feb 23 18:55
I don't care for it either. It's just all I knew at the time and the intranet page is hosted via IIS
Markus Kiili
@Masd925
Feb 23 19:06
@JLuboff I was in an interview this week. They had 3 or four kinds of coffee there and no php in the house.
Jason Luboff
@JLuboff
Feb 23 19:07
@Masd925 Sounds blissful! I've only started drinking coffee...don't really enjoy it..but..need the caffefine on some days..
Tiago Correia
@tiagocorreiaalmeida
Feb 23 21:48
hello everyone
@Masd925 that's the right one :D
https://github.com/tiagocorreiaalmeida/music-review/blob/master/client/src/components/EditPostPage.js what would be the best way to move the usero ut of the page if the post doesnt exist on the props? I tried with componentWillMount and others but it runs before the first code and trhows errors cause the post isnt defined
Jason Luboff
@JLuboff
Feb 23 22:17
:fire:
May Kittens Devour Your Soul
@diomed
Feb 23 22:32
Jason Luboff
@JLuboff
Feb 23 23:19
@tiagocorreiaalmeida Line 197 for your mail template...whats with all the white sapce