These are chat archives for FreeCodeCamp/HelpJavaScript

8th
Aug 2018
Prakash Kumar
@ThePrakashKumar
Aug 08 2018 06:37

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object

class Book {
  constructor(author) {
    this._author = author;
  }
  // getter
  get writer(){
    return this._author;
  }
  // setter
  set writer(updatedAuthor){
    this._author = updatedAuthor;
  }
}
const lol = new Book('anonymous');
console.log(lol.writer);  // anonymous
lol.writer = 'wut';
console.log(lol.writer);  // wut

Why they are using _ here?

What is wut here?
Blauelf
@Blauelf
Aug 08 2018 06:56
@ThePrakashKumar _ is often prepended to mark "private" properties (which aren't private at all, it's more to signal "keep away", and hope the other one respects that)
Aditya
@ezioda004
Aug 08 2018 07:06
IIRC theres a proposal for private fields with # is prefix, which most people hate.
Dan Couper
@DanCouper
Aug 08 2018 07:35
I can't quite believe that example is still up. "wut" is the new name of the writer that's being set @ThePrakashKumar. It stated off as "anonymous", then was set to wut. It's a very half-arsed example
Note that it's a very badly written challenge @ThePrakashKumar, there have been a few issues raised about it but they're in the middle of moving the codebase around so nothing's being done to fix it atm.
Jen
@jenniredfield
Aug 08 2018 08:52
@Blauelf do you program in other languages too?
Prakash Kumar
@ThePrakashKumar
Aug 08 2018 08:53
@Blauelf @ezioda004 @DanCouper thanks for your help.
catalin560
@catalin560
Aug 08 2018 09:24

hey guys! is anyone experienced with python here?
can someone translate this python code to javascript:

q = { 1: [[1]] }

def decompose(n):
    try:
        return q[n]
    except:
        pass

    result = [[n]]

    for i in range(1, n):
        a = n-i
        R = decompose(i)
        for r in R:
            if r[0] <= a:
                result.append([a] + r)

    q[n] = result
    return result

more exactly this part:

for i in range(1, n):
        a = n-i
        R = decompose(i)
        for r in R:
            if r[0] <= a:
                result.append([a] + r)
Blauelf
@Blauelf
Aug 08 2018 10:20
Almost 1:1 version:
const q = { 1: [[1]] };

function decompose(n) {
    if (n in q)
        return q[n];

    const result = [[n]];

    for (let i = 1; i < n; i++) {
        const a = n-i;
        const R = decompose(i);
        for (let r of R)
            if (r[0] <= a)
                result.push([a].concat(r));
    }

    q[n] = result;
    return result;
}
Dan Couper
@DanCouper
Aug 08 2018 10:31

you can get an almost exact 1-to-1 translation that works exactly the same way as the Python version (bar curly brackets and needing to use const/let) by defining range as well

function * range(counter, end) {
    while(counter <= end) {
        yield counter;
        counter++;
    }
}

then you can do

```
for (const i of range(1, n)) {

}

catalin560
@catalin560
Aug 08 2018 10:32
@Blauelf I saw your answer in the python channel, thank you very much for the 1:1 translation!
Dan Couper
@DanCouper
Aug 08 2018 10:32
Ugh Gitter 😐 for (const i of range(1, n)) {
Blauelf
@Blauelf
Aug 08 2018 10:32
@DanCouper Would be < end, I guess.
Dan Couper
@DanCouper
Aug 08 2018 10:33
Come back to Gitter like a year after I was last on and still can't type multi line stuff into the app, raging
Blauelf
@Blauelf
Aug 08 2018 10:35
range used to be the ugly twin, building the whole list in memory, while xrange was generator-based. Now range is a class (Python inserts the new automatically).
Means if I want an actual list, I have to wrap it in list. Kind of like what [...arguments] does.
Yashwardhan Pauranik
@yashwp
Aug 08 2018 12:31
alpox
@alpox
Aug 08 2018 16:15
@yashwp use onload instead of onloadend
@yashwp and use readDataUrl
readAsDataUrl*
Abhiinfo
@Abhiinfo
Aug 08 2018 16:43
Hi can someone help me with this? I want to allow file uploads in a form. I want it to start with 1 file upload option displayed, and then if the user clicks on a link, another one upload is displayed below that one. I want it all to be dynamic and create the html on the fly and use dynamic data.
Brad
@bradtaniguchi
Aug 08 2018 16:44
@Abhiinfo are you using a framework/jquery or vanillajs
Abhiinfo
@Abhiinfo
Aug 08 2018 16:44
jquery actually @bradtaniguchi
Brad
@bradtaniguchi
Aug 08 2018 16:45
prolly would want to start getting the single file upload working with your backend, something as basic as <input type="file" name="myFile"> would get your going
Abhiinfo
@Abhiinfo
Aug 08 2018 16:45
@bradtaniguchi I have found a link but going through it I didn't understand it completely...Also I did not get how to retrieve all selected documents on the js side..
Brad
@bradtaniguchi
Aug 08 2018 16:47
do you need to care about what was selected with jquery?
Abhiinfo
@Abhiinfo
Aug 08 2018 16:47
@bradtaniguchi A normal file upload needs to upload the content everytime and hit the server again and again..however what I need is multiple file uploads from multiple folders at once and then collect those files in an array and send to server via ajax
@bradtaniguchi I did not understand your question..can you please elaborate?
Brad
@bradtaniguchi
Aug 08 2018 16:48
what you said answered my question
technically you can provide the multipleattribute so the user can select multiple files during upload. And the file only gets uploaded when you submit the form (like any other form input)
but this is all just HTML5, no js required. If you wanted to get the form-value using jquery it should still work out, obviously you'll need to handle the file-data differently when sending the data tho
Abhiinfo
@Abhiinfo
Aug 08 2018 16:50
Sure....can you please provide me with a subtle solution for this....I know that inorder to get the images or documents saved to mysql I have to convert the documents to base64 format but what i do not knw is how to select all documents at jquery side when they are coming dynamically with different id and different name
Abhiinfo
@Abhiinfo
Aug 08 2018 16:51
@bradtaniguchi multiple attribute is to select multiple documents from same folder and so its not complete use to me
Brad
@bradtaniguchi
Aug 08 2018 16:51
yea I kinda figured
in that case, youd probably would want to dynamically create more input fields using jquery
but I would worry more about getting 1 file-field to work, than how your doing multiple (extra layer of complexity)
Abhiinfo
@Abhiinfo
Aug 08 2018 16:52
yes that is what I am asking for..how to fetch files in that case
@bradtaniguchi Can you see the link what I have posted..may be you can understand things from it and guide me
how to fetch files from it as I tried using the var inputFile = $("input type=[file]").val(); but it did not work............using ID gets me value for only first file cz others get dynamic id everytime
Brad
@bradtaniguchi
Aug 08 2018 16:55
I dislike reading that guide, its extremely outdated. It might still be relevant, but a lot has happened since then (HTML5 wasn't release at the time of this guide, for another 6 years!)
Abhiinfo
@Abhiinfo
Aug 08 2018 16:56
Sure I understand..is there any easy solution for it?
Brad
@bradtaniguchi
Aug 08 2018 16:57
you already said you can get the value for the first id, but you should be able to just generate an id for each input-field that is created. A basic counter would work
Abhiinfo
@Abhiinfo
Aug 08 2018 16:58
@bradtaniguchi Sure will check into that...Thanx Brad for help
Brad
@bradtaniguchi
Aug 08 2018 16:58
np, goodluck :D
Jason Luboff
@JLuboff
Aug 08 2018 17:04
Morning!
Christopher McCormack
@cmccormack
Aug 08 2018 17:05
@JLuboff did you accidentally stumble into an adventure this morning??
Jason Luboff
@JLuboff
Aug 08 2018 17:05
@cmccormack You could say that, took my Microsoft exam (70-761 Querying T-SQL)
Christopher McCormack
@cmccormack
Aug 08 2018 17:06
@JLuboff pass?
Jason Luboff
@JLuboff
Aug 08 2018 17:08
Yup!
Abhiinfo
@Abhiinfo
Aug 08 2018 17:10
Hi...Can anyone suggest how to get value from a file input without using id and class attribute
Christopher McCormack
@cmccormack
Aug 08 2018 17:10
Nice! :fireworks:
Was it tough?
Brad
@bradtaniguchi
Aug 08 2018 17:14
@Abhiinfo data attribute?
or by form name attribute
Jason Luboff
@JLuboff
Aug 08 2018 17:15
@cmccormack Probably the toughest MS exam I've taken to date
Christopher McCormack
@cmccormack
Aug 08 2018 17:16
Ouch
do they give you a percentage or anything? did you nail it?
Jason Luboff
@JLuboff
Aug 08 2018 17:16
I got an 830, passing is 700
Christopher McCormack
@cmccormack
Aug 08 2018 17:16
damn nice job
Jason Luboff
@JLuboff
Aug 08 2018 17:16
I had seen probably 50% of the questions prior
The other half were either new, or variations on questions but set up in a way that the answer would be completely different
Abhiinfo
@Abhiinfo
Aug 08 2018 17:17
@bradtaniguchi Actually the form name is dynamic here .... I used ("input type=[file]").val() but its not working
Christopher McCormack
@cmccormack
Aug 08 2018 17:18
@Abhiinfo input[type=file]?
Abhiinfo
@Abhiinfo
Aug 08 2018 17:19
@cmccormack Actually it selects all files with input type file but how to get values from it ?
Moisés Man
@moigithub
Aug 08 2018 17:20
is val ?? or value ?
a method() or attribute ?
using vanilla JS or some library (ie. jquery)
Abhiinfo
@Abhiinfo
Aug 08 2018 17:20
The problem occurs cz here both id and name are dynamic
Christopher McCormack
@cmccormack
Aug 08 2018 17:20
@Abhiinfo yes need more info like @moigithub states
Abhiinfo
@Abhiinfo
Aug 08 2018 17:20
@moigithub ya value in vanillaJS and val() in jquery but how to use them when name and id are dynamic
Moisés Man
@moigithub
Aug 08 2018 17:21
maybe it returning a single node.. or a nodelist (seems like an array) ?
console.log (or console.dir ) to check
Abhiinfo
@Abhiinfo
Aug 08 2018 17:22
a single node everytime I click on an item
Christopher McCormack
@cmccormack
Aug 08 2018 17:23
@Abhiinfo how are you using this selector?
Abhiinfo
@Abhiinfo
Aug 08 2018 17:23
image.png
this is the html code
Christopher McCormack
@cmccormack
Aug 08 2018 17:23
@Abhiinfo selector in js
Abhiinfo
@Abhiinfo
Aug 08 2018 17:25
@cmccormack https://www.bennadel.com/blog/1375-ask-ben-dynamically-adding-file-upload-fields-to-a-form-using-jquery.htm ...................this is teh js code from where i took a reference
What I am not getting we can use a selector but only when we knw an id or class...but how to use it when both of id and class are dynamic
Moisés Man
@moigithub
Aug 08 2018 17:25
sometimes easier to check if u drop ur code on codepen (or something similar) and share the link
Abhiinfo
@Abhiinfo
Aug 08 2018 17:26
cz by that way we will get the value of only first input and not for the rest
Christopher McCormack
@cmccormack
Aug 08 2018 17:27
@Abhiinfo they seem to have unique names right? Can you iterate over the different file inputs returned in your selector and find the one with the name you need?
Abhiinfo
@Abhiinfo
Aug 08 2018 17:27
@moigithub Yes I completely understand your point ....
@cmccormack I need the value of all file inputs actually
and then push them into an arraylist at once and send to server via ajax
Christopher McCormack
@cmccormack
Aug 08 2018 17:28
@Abhiinfo we need to know your selector method
if you aren't using a method that returns all instances that may be your issue
just paste the JS code that contains that selector...
Abhiinfo
@Abhiinfo
Aug 08 2018 17:28
@cmccormack Thats the only thing I am also asking..what selector shall I use cz everyting is dynamic
Sure

$(document).ready(function(){
var jAddNewUpload = $( "#add-file-upload" );
jAddNewUpload
.attr( "href", "javascript:void( 0 )" )
.click(
function( objEvent ){
AddNewUpload();
objEvent.preventDefault();
return( false );
}
);
})

function AddNewUpload(){
var jFilesContainer = $( "#files" );
var jUploadTemplate = $( "#element-templates div.row" );
var jUpload = jUploadTemplate.clone();
var strNewHTML = jUpload.html();
var intNewFileCount = (jFilesContainer.find( "div.row" ).length + 1);
jUpload.attr( "id", ("file" + intNewFileCount) );
strNewHTML = strNewHTML
.replace(
new RegExp( "::FIELD2::", "i" ),
intNewFileCount
)
.replace(
new RegExp( "::FIELD3::", "i" ),
("presoFile" + intNewFileCount)
);
jUpload.html( strNewHTML );
jFilesContainer.append( jUpload );
}

Christopher McCormack
@cmccormack
Aug 08 2018 17:29
@Abhiinfo I would probably use querySelectorAll
@Abhiinfo please don't paste all code just the relevent portions
Brad
@bradtaniguchi
Aug 08 2018 17:31
@Abhiinfo I mentioned you should generate your own id/selector for each input. And use that to get the values of each of the inputs. You last mentioned your just using input type=[file] but that will just get you all of them
Abhiinfo
@Abhiinfo
Aug 08 2018 17:31
@cmccormack I got this code from the previous link and in this they have just showed the selector for first finput type=file elements other elements comes dynamic
@bradtaniguchi What i want to knw is querySelectorAll is fine but with what shall i use it...will it work with to get the value??
I need to know an selector to use it and here Its all dynamic
Christopher McCormack
@cmccormack
Aug 08 2018 17:35
looks to me that they're using a template and modifying the filename in that template then appending it to the body somewhere
Abhiinfo
@Abhiinfo
Aug 08 2018 17:37
Yes they are actually making a clone of the DOM node and then changing the id and name everytime they append it to DOM again
Christopher McCormack
@cmccormack
Aug 08 2018 17:39
So in your case you already have several file inputs and you want to get the value of each, or only one?
Abhiinfo
@Abhiinfo
Aug 08 2018 17:40
for each one of them and it depends on user how many inputs he can give but i need to need to receive all the inputs at the server side
Simon Cordova
@gbsimon87
Aug 08 2018 17:43
What's up what's up
Brad
@bradtaniguchi
Aug 08 2018 17:43
how should I tell my coworker were going to re-do all of his work since its terrible? :/
Christopher McCormack
@cmccormack
Aug 08 2018 17:44
@bradtaniguchi fire him
@gbsimon87 heya
@Abhiinfo can you give each input an id or data-* value so you know what you need? Your requirements are a bit confusing, so maybe someone here will understand and be able to help
Abhiinfo
@Abhiinfo
Aug 08 2018 17:46
I am so sorry but I have tried even an easy solution for this as
image.png
Simon Cordova
@gbsimon87
Aug 08 2018 17:47
@cmccormack whats happening
First day done! :)
Christopher McCormack
@cmccormack
Aug 08 2018 17:47
@gbsimon87 trying to figure out why my port channels aren't working :(
@gbsimon87 first day of what?
Simon Cordova
@gbsimon87
Aug 08 2018 17:47
Went well, I found a bug on a page design thy are creating, I think it made me look good
New role
Christopher McCormack
@cmccormack
Aug 08 2018 17:48
@gbsimon87 woah that was quick!
I must have missed a few days here :)
Jason Luboff
@JLuboff
Aug 08 2018 17:49
@bradtaniguchi "Hey dingus, your code sucks. We're redoing it"
Simon Cordova
@gbsimon87
Aug 08 2018 17:49
I ended up getting 4 offers for a sponsorship since Friday! After 2 months of 0
Now I'm I'm a debate, because one offer is ÂŁ15k more a year but a huge international company, while this one is more tight knit and 20 mins from home
Christopher McCormack
@cmccormack
Aug 08 2018 17:51
@gbsimon87 international companies can still be fun to work for
Jason Luboff
@JLuboff
Aug 08 2018 17:51
15k more a year..is a lot
Christopher McCormack
@cmccormack
Aug 08 2018 17:53
commute makes a big diff though
I hated my commute when I had to go in 4-5 days a week
Almost left the company for another company for the same pay but foregoing my bonus, but they offered me full remote so stayed
Simon Cordova
@gbsimon87
Aug 08 2018 17:54
Yeah, I mean it's a 15min bike or bus ride to an hour and a half on subway
Jason Luboff
@JLuboff
Aug 08 2018 17:54
Oh... 1.5 hours...ya..thats a bit tough
Simon Cordova
@gbsimon87
Aug 08 2018 17:54
And this current company allows me 2 days remote after 3 months with them
Jason Luboff
@JLuboff
Aug 08 2018 17:54
Commutes do suck
Simon Cordova
@gbsimon87
Aug 08 2018 17:55
My last job was a 12 min walk and all I really needed to do was cross tower Bridge so that was pretty sweet everyday
Jason Luboff
@JLuboff
Aug 08 2018 17:55
My job is ~10-12 minute drive from home.
Christopher McCormack
@cmccormack
Aug 08 2018 17:55
just consider it to be you paying for a better commute and it could change the perspective
and paying Gross, not Net
Simon Cordova
@gbsimon87
Aug 08 2018 17:56
Yeah, 3 hours a day commute will take all my time. Here it's 9-6 with an hour lunch, so getting home earliest at 7:30 may cause dilemma with the lady too
Understandably so I suppose.
Brad
@bradtaniguchi
Aug 08 2018 17:57
Not going to lie, but time > money
Simon Cordova
@gbsimon87
Aug 08 2018 17:57
Yeah, I just feel like 15 hours a week of my life commuting isn't worth 15 grand
Brad
@bradtaniguchi
Aug 08 2018 17:57
especially at a certain point. (obviously being unemployeed is only time, but no money haha)
Christopher McCormack
@cmccormack
Aug 08 2018 17:58
15 grand minus taxes :)
Simon Cordova
@gbsimon87
Aug 08 2018 17:58
On that same token, that 15 grand would cover my years rent
True, and I'd be a bracket higher and they don't play around with taxes in England.
On other news, tried VS today all day, I like it, nice to have the terminal, can't quite see other advantages to sublime though just yet
Jason Luboff
@JLuboff
Aug 08 2018 18:00
Atom all day er-day
Christopher McCormack
@cmccormack
Aug 08 2018 18:01
@gbsimon87 VS or VS Code?
Jason Luboff
@JLuboff
Aug 08 2018 18:02
My guess... VS Code.. personally I wouldn't use VS for JS
Christopher McCormack
@cmccormack
Aug 08 2018 18:02
VS Code blows both out the water you guys are nuts! nutS!!
VS Code to Atom or Sublime are like moving from Word to Etch-A-Sketch
Jason Luboff
@JLuboff
Aug 08 2018 18:03
To each their own :)
Christopher McCormack
@cmccormack
Aug 08 2018 18:07
Agreed as long as it brings you joy
Tom
@moT01
Aug 08 2018 18:08
started using vs code recently
i think im being swayed
Brad
@bradtaniguchi
Aug 08 2018 18:08
:+1:
Christopher McCormack
@cmccormack
Aug 08 2018 18:10
@moT01 sway
Brad
@bradtaniguchi
Aug 08 2018 18:16
join the dark side muhaha
Tom
@moT01
Aug 08 2018 18:20
im in
put dark mode add-on to my firefox, and im liking it
turn almost all websites dark
Kudzu
@czhower
Aug 08 2018 18:21
VS Code is very nice. I prefer it over VS Ent for many things
VS Code is a very nice modern update to 80s coding.
Christopher McCormack
@cmccormack
Aug 08 2018 18:26
I just like how simple they make extensions, the terminal, git, etc...
Kudzu
@czhower
Aug 08 2018 18:27
its very simplistic and open.... thats the beauty.
VS Ent is a major PITA to extend in comparison.
Especially custom debuggers.....
Christopher McCormack
@cmccormack
Aug 08 2018 18:28
I need to use more debuggers...
Jason Luboff
@JLuboff
Aug 08 2018 18:28
I wanted to install SQL tools for VS Community (essentially Ent but free) and it was retardly difficult and unclear. Had to first install SSDT and then had to go and find a seperate extensions to get the templates but not before having to uninstall and reinstall shit
Christopher McCormack
@cmccormack
Aug 08 2018 18:28
too easy to throw a log in
Kudzu
@czhower
Aug 08 2018 18:31
yep
Brad
@bradtaniguchi
Aug 08 2018 18:32
yea same here
Christopher McCormack
@cmccormack
Aug 08 2018 18:32
React dev tools are kind of nice as you can see state when you click something or whatever
Jason Luboff
@JLuboff
Aug 08 2018 18:38
When using async/await with my routes in express.. should I also be using it on loops (foreach/map/filter/etc) if that loop is interacting with a promise? My thought is yes...
Brad
@bradtaniguchi
Aug 08 2018 18:39
sounds kinda fishing, what exactly are you doing where you need a loop with async stuff?
Jason Luboff
@JLuboff
Aug 08 2018 18:40
Making multiple (database) inserts
a.forEach(async (approver) => {
          await insert.approvalPersons(requestID, approver.PersonID);
        });
Christopher McCormack
@cmccormack
Aug 08 2018 18:41
@JLuboff can you not insert them all in one request?
Jason Luboff
@JLuboff
Aug 08 2018 18:42
Maybe with dynamic SQL...but.. I'm not versed in that
If I knew that approvers would always be a fixed number I could, but it can chagne in the future
And I'd rather not have to change code to handle that
Brad
@bradtaniguchi
Aug 08 2018 18:43
I would definitely look into a bulk insert otherwise if you don't care about the order of insertion you can use Promise.allso you do it all "at the same time"
Christopher McCormack
@cmccormack
Aug 08 2018 18:43
i'm not sure your async/await above would do anything
Brad
@bradtaniguchi
Aug 08 2018 18:43
but yea Idk much about async await past the base case
Christopher McCormack
@cmccormack
Aug 08 2018 18:43
it's still going to iterate through the array and run the callback immediatly
Jason Luboff
@JLuboff
Aug 08 2018 18:44
Ok, i'm just still new to async/await so wasn't sure if it would be needed
Christopher McCormack
@cmccormack
Aug 08 2018 18:44
(I think)
Brad
@bradtaniguchi
Aug 08 2018 18:44
@cmccormack what about whatever is after this code tho, its not waiting for anything right?
Christopher McCormack
@cmccormack
Aug 08 2018 18:44
right
you can await on the a.forEach I believe
as long as the function is async
hmm
I"m not even 100% on that :)
but easy to test
Jason Luboff
@JLuboff
Aug 08 2018 18:45
This is the entire try block
try {
        const result = await insert.newRequest(requestBody);
        const a = await read.approvers(requestBody.location);

        const requestID = result.RequestID;
        const emails = a.map(e => e.Email);
        const mailBody = {
          requestor: requestBody.requestor,
          location: req.body.requestLocation.Name,
          emergency: requestBody.emergency === 1,
          temporary: requestBody.changePermanent === 0,
          link: requestID,
        };

        a.forEach(async (approver) => {
          await insert.approvalPersons(requestID, approver.PersonID);
        });

        nodeMailer.newRequest(emails, mailBody);
        return res.sendStatus(200);
      }
So really.. the rest doesn't have to wait for the loop to finish..
Christopher McCormack
@cmccormack
Aug 08 2018 18:48
so yeah you can put await on the forEach codepen
Jason Luboff
@JLuboff
Aug 08 2018 18:49
Ok, but I guess... any need to?
Christopher McCormack
@cmccormack
Aug 08 2018 18:49
oh I haven't read your code, was making that pen haha
I'm not certain why you need async await at all in that case
for the forEach I mean
Brad
@bradtaniguchi
Aug 08 2018 18:50
The main thing I would care about is what if the first/ or any of the inserts fail, you send 200
right?
well I guess not, youd get kicked to the catch block, nevermind haha
Jason Luboff
@JLuboff
Aug 08 2018 18:50
@bradtaniguchi Mmm.. it should be caught if thats the case
but thats not to say that I wouldn't have inserted some already
Removed async/await, seems it shouldn't be needed :thumbsup:
Christopher McCormack
@cmccormack
Aug 08 2018 18:53
I think you may have to use a for loop if you wanted to wait for each insert to complete, but I"m not sure
not that you're trying to, but now I'm curious :)
Jason Luboff
@JLuboff
Aug 08 2018 18:54
Curiousity killed the cat. And curious george. Curious george is dead.
Chris
@crokita
Aug 08 2018 18:55
lol
Christopher McCormack
@cmccormack
Aug 08 2018 18:56
Poor monkey
Simon Cordova
@gbsimon87
Aug 08 2018 19:04
Hey guys sorry got home and had to assemble a couch
I meant VS code, don't even know what VS is tbh
Jason Luboff
@JLuboff
Aug 08 2018 19:04
Already spending them big bucks on a couch eh?>
Brad
@bradtaniguchi
Aug 08 2018 19:10
my killer extensions for VSCode is prettier, typescript (duh), gitlens, editor config, and I really really want to try live share with someone haha
sorry not editor config, settings sync. I have the exact same vscode setup on like 4 machines
just realized in vscode, if a filepath appears from a stack-trace in your terminal you can ctrl+click on it to go to the line
Fikry82
@Fikry82
Aug 08 2018 19:13
hi
i need help with golf game ??
Jason Luboff
@JLuboff
Aug 08 2018 19:14
@Fikry82 What do you have so far./ whats your question?
Fikry82
@Fikry82
Aug 08 2018 19:15
my English not so good
what is par mean and stroke mean ?
Jason Luboff
@JLuboff
Aug 08 2018 19:15
strokes is the total number of times a person hits the ball for a single hole, par is how many strokes it should take to complete
Fikry82
@Fikry82
Aug 08 2018 19:19
so strokes = hits
par = total of hits
Jason Luboff
@JLuboff
Aug 08 2018 19:19
not quite. strokes equals total number of hits, par is the expected number of hits
Fikry82
@Fikry82
Aug 08 2018 19:20
:)
zzzzzz
Jason Luboff
@JLuboff
Aug 08 2018 19:20
So if par is 3, that means to be on par, you would need to have strokes be 3 meaning you hit the ball 3 times to get it in the hole, which is the expected number of hits
Fikry82
@Fikry82
Aug 08 2018 19:21
what i if hit the ball more or less
if par 3 and strokes 5 or 2
Fikry82
@Fikry82
Aug 08 2018 19:30
var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
function golfScore(par, strokes) {
  // Only change code below this line
  if(strokes == 1){
    return names[0];
  }else if(strokes <= par -2){
    return names[1];
  }

  return "Change Me";
  // Only change code above this line
}

// Change these values to test
golfScore(5, 4);
Christopher McCormack
@cmccormack
Aug 08 2018 19:36
@Fikry82 in my opinion you are overcomplicating it by adding an array
@Fikry82 if par is 3 and strokes is 5, you would have a double bogey.
Christopher McCormack
@cmccormack
Aug 08 2018 19:41
@Fikry82 you can follow the order of your array - if par is in the middle, then Birdie would be par -1, Eagle par -2, Bogey par + 1, Double Bogey par + 2, etc...
Fikry82
@Fikry82
Aug 08 2018 19:47
var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
function golfScore(par, strokes) {
  // Only change code below this line
  if(strokes == 1){
    return names[0];
  }else if(strokes == par -1){
    return names[2];
  }else if(strokes == par -2){
    return names[1];
  }  else if(par == strokes){
    return names[3];
  }else if(strokes == par + 1){
     return names[4];
  }else if(strokes == par + 2){
     return names[5];
  }else{
     return names[6];
  }
  return "Change Me";
  // Only change code above this line
}
what's wrong ?
Christopher McCormack
@cmccormack
Aug 08 2018 19:49
@Fikry82 you tell us -what is returning?
Fikry82
@Fikry82
Aug 08 2018 19:50
its okay it works now :)
(strokes <= par-2)
Christopher McCormack
@cmccormack
Aug 08 2018 19:50
@Fikry82 :thumbsup:
@Fikry82 a suggestion - if you are going to return in a conditional, there is no need to use else if after
the return will end the function anyhow, so you can just use multiple if statements
Fikry82
@Fikry82
Aug 08 2018 19:51
yea right
Christopher McCormack
@cmccormack
Aug 08 2018 19:52
A switch could make it cleaner as well, but that's a personal preference if you want to use switch over multiple if
Fikry82
@Fikry82
Aug 08 2018 19:52
its my next lesson :)
Christopher McCormack
@cmccormack
Aug 08 2018 19:52
ah ok
Fikry82
@Fikry82
Aug 08 2018 19:52
wish me luck
Christopher McCormack
@cmccormack
Aug 08 2018 19:52
:four_leaf_clover:
Rogério Dalot
@Dalot
Aug 08 2018 19:53
if(strokes == 1) return names[0];

  else if( strokes == par -1 ) return names[2];
  else if( strokes == par -2 ) return names[1];
  else if( par == strokes ) return names[3];

.......
you can see the improved readibility on something like that
Fikry82
@Fikry82
Aug 08 2018 19:55
if i finished all java script Curriculum can i call myself javascript programmer
Rogério Dalot
@Dalot
Aug 08 2018 19:56
There is no need on that amount of code to be so nit-picking but with time, you will see its importance
Christopher McCormack
@cmccormack
Aug 08 2018 19:56
@Dalot you still don't need the else if when returning after each condition
Fikry82
@Fikry82
Aug 08 2018 19:56
@Dalot but where is the if { } ???
Rogério Dalot
@Dalot
Aug 08 2018 19:57
In my opinion, you can call yourself a JS programmer when you are able to solve problems in real world, if the JS curriculum helps? Probably does
@cmccormack yeah true that!
@Fikry82 you do not need that, actually you can do like this, as @cmccormack stated
Jason Luboff
@JLuboff
Aug 08 2018 20:01
If you’re block of code is a single statement, you don’t need the curly braces
Fikry82
@Fikry82
Aug 08 2018 20:02
@JLuboff but he writ it in multi lines
Rogério Dalot
@Dalot
Aug 08 2018 20:05
If the condition is not met, the engine the compiler will jump that line, which you can see it ends with the semi-colo
semi-colon*
Simon Cordova
@gbsimon87
Aug 08 2018 20:06
@JLuboff I don't mean to be rude I keep going off I'm just so caught up - catch up tomorrow be safe buds
Brad
@bradtaniguchi
Aug 08 2018 20:10
Id use a switch statement when the if/else block is over like 3
Christopher McCormack
@cmccormack
Aug 08 2018 20:10
@bradtaniguchi deeply nested ternary for me!
Brad
@bradtaniguchi
Aug 08 2018 20:10
but then now that I look at it the condition might not work, hehe
@cmccormack hey that's what I do when I wanna feel pro programmer :trollface:
Christopher McCormack
@cmccormack
Aug 08 2018 20:10
haha
switch(true)
Blauelf
@Blauelf
Aug 08 2018 20:14
@cmccormack I've seen that as an ugly alternative to if-else chains that could utilize fall-through.
Christopher McCormack
@cmccormack
Aug 08 2018 20:14
it's not that ugly :)
but ideally you would find something else instead, I would never really use multiple if statements but instead maybe an array or something
Blauelf
@Blauelf
Aug 08 2018 20:15
Fall-through has a tendency of not being intended, and it's sometimes hard to determine whether it is in this particular case.
And all those break; statements in my opinion are not really better or worse than else if chains, just different.
Brad
@bradtaniguchi
Aug 08 2018 20:19
i don't always use switch, but when I do, I just use return
Christopher McCormack
@cmccormack
Aug 08 2018 20:24
@Blauelf that's why I tend to avoid switches and if statements and for loops, side effects are bad
Blauelf
@Blauelf
Aug 08 2018 20:24
You use while loops instead? :D
Christopher McCormack
@cmccormack
Aug 08 2018 20:25
map/reduce/filter
Blauelf
@Blauelf
Aug 08 2018 20:25
forEach with side-effects? XD
Christopher McCormack
@cmccormack
Aug 08 2018 20:25
rarely
usually try to design it so I don't NEED to create side-effects
but I'm still a novice functional programmer :)
or whatever is newbier than novice
Jason Luboff
@JLuboff
Aug 08 2018 20:26
@Fikry82 I should of specified, the block of code that is within the if/else if/ else statement
newmoon
@newmoon
Aug 08 2018 20:34
Seems that can be done with a map/array:
var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
function golfScore(par, strokes) {
  if(strokes !== 1 && strokes <= par - 2) strokes = par - 2;
  const score = [1, par - 2, par - 1, par, par + 1, par + 2];
  return names[score.indexOf(strokes)] || "Go Home!";
}
Usually good to avoid lots of if/else if possible. Not a fan of switch statements either :)
Christopher McCormack
@cmccormack
Aug 08 2018 20:38
hmm does this take into account a par 5 in 2 strokes? Double Eagle or Albatross?
newmoon
@newmoon
Aug 08 2018 20:38
haha, some room for improvement it seems
Christopher McCormack
@cmccormack
Aug 08 2018 20:39
not just yours but the FCC exercise as well
newmoon
@newmoon
Aug 08 2018 20:39
oh, didn't realize this was a FCC exercise. I should try out some of those
Jason Luboff
@JLuboff
Aug 08 2018 20:53

Alright...here's another question for everyone.. when working in dev mode.. I want to make it so that my mailing is either disabled or only sent to myself. I have this function

function sendMail(subject, message) {
  return async (to, body) => {
    try {
      const isVerified = await transporter.verify();
      if (!isVerified) throw new Error('The SMTP service is currently not available');

      const html = typeof message === 'function'
        ? message(to, body)
        : message;

      const mailSubject = typeof subject === 'function'
        ? subject(body)
        : subject;
        /* eslint-disable */
        to = process.env.NODE_ENV === 'production' ? to : 'jluboff@potato.com';
        /* eslint-enable */

      const info = await transporter.sendMail({
        subject: mailSubject, to, bcc: 'jluboff@potato.com', html, from: 'Request@potato.com',
      });
      console.log(info); 
    } catch (err) {
      console.error('Mail Send Failed: ', err.message);
    }
  };
}

So my thoughts are this.. either 1. I have the function as above with this line to = process.env.NODE_ENV === 'production' ? to : 'jluboff@potato.com'; or 2. I have a seperate mail file with duplicate exports but disabled mailing or whatever and whereever I have const nodeMailer = require('./myfile') I have const nodeMailer = process.env.NODE_ENV === 'production' ? require('./myFile') : require('./myfileDev');
What is the better solution?

Christopher McCormack
@cmccormack
Aug 08 2018 21:07
@JLuboff I would probably define where the email was going to go outside of the function
so you can setup a default to based on your environment, then you can use something like defaultto || to in your ternary
but either way is probably fine, I just don't like to do production checks inside my code when avoidable
I guess that expression would go in your sendMail not a ternary
Jason Luboff
@JLuboff
Aug 08 2018 21:14
@cmccormack The to is defined outside the function but many functions use this helper function (if that makes sense)
Christopher McCormack
@cmccormack
Aug 08 2018 21:14
to is also in your callback parameters
Jason Luboff
@JLuboff
Aug 08 2018 21:15
True true
Christopher McCormack
@cmccormack
Aug 08 2018 21:16
so if you have to in callback, you want to use the local to only if in production, else use a default right?
Jason Luboff
@JLuboff
Aug 08 2018 21:16
Pretty much, I think. Lol
I have a default set, but as a backup not necessarily if production vs dev
I actually have return async (to = 'jluboff@potato.com', body) => {...
But that only works if nothing is in the to field from the function that calls it
And I'd have to stop that else where in code, and in a lot of places
Christopher McCormack
@cmccormack
Aug 08 2018 21:19
I don't think you should hardcode it in there
probably better to put it in your .env file
@JLuboff can you create the sendMail object outside the function using defaults then merge later?
Object.assign
only add defaults depending on the environment of course
Jason Luboff
@JLuboff
Aug 08 2018 21:22
sendMail is a function, not an object though? (Full disclosure, I might be a little tired so may not be fully following correctly here)
Christopher McCormack
@cmccormack
Aug 08 2018 21:23
yes you might be
haha
sendMail is called with an object
Simon Cordova
@gbsimon87
Aug 08 2018 21:24
We should have a get together one day and nerd out
Jason Luboff
@JLuboff
Aug 08 2018 21:25
@cmccormack I think I'm going to take a break from it for now lol
Simon Cordova
@gbsimon87
Aug 08 2018 21:25
@Blauelf and I are in Europe so it sounds like a good spot !
Christopher McCormack
@cmccormack
Aug 08 2018 21:25
@gbsimon87 I'll go back but not in August! I went to Vienna a few years ago in August and it was hot, muggy, and no airconditioning anywhere
Simon Cordova
@gbsimon87
Aug 08 2018 21:26
I love Vienna, could be the most beautiful city I've ever visited
Budapest is up there too though, and old Prague
Yeah maybe later on sometime, @JLuboff get on board buds!
Christopher McCormack
@cmccormack
Aug 08 2018 21:26
I went to Budapest too! We went to one of those swimming pools in a castle things
was beautiful
Vienna was so awesome, I love greek mythology and they have statues everywhere depicting it
Jason Luboff
@JLuboff
Aug 08 2018 21:27
Man... its going to be a while until I go to Europe again
Come over here, @cmccormack and I are only like 6-7 hours apart I think
Christopher McCormack
@cmccormack
Aug 08 2018 21:28
yeah that's true come down here
Simon Cordova
@gbsimon87
Aug 08 2018 21:28
I'm actually going to Toronto late this month and headed to milwaukee for a bit, maybe I could go West a bit tbh
Tbh**
Arizona is really close to California no? Same divisions in sports I'm pretty sure
Jason Luboff
@JLuboff
Aug 08 2018 21:29
One state over
Christopher McCormack
@cmccormack
Aug 08 2018 21:30
Yeah only a few hours to the East side of Cali from here
but California is huge
Jason Luboff
@JLuboff
Aug 08 2018 21:30
California is quite large..
Christopher McCormack
@cmccormack
Aug 08 2018 21:30
12 hours to visit my brother in Modesto
Jason Luboff
@JLuboff
Aug 08 2018 21:31
from furthest south to further north... is probably... 13-14 hours? I know from here to SF is 6-7 hours... and from here to the border is 3-4 hours..so thats 9-11 hours there and SF is still couple hours from the border
Simon Cordova
@gbsimon87
Aug 08 2018 21:31
50 something votes for a reason lol
I'll see what I can actually schedule though seriously speaking, never been out west anyway
Depends on what kind of flight I can get - not driving for days
Christopher McCormack
@cmccormack
Aug 08 2018 21:41
it's a boring drive too from most places
Jason Luboff
@JLuboff
Aug 08 2018 21:42
Definitely boring
I can't remember if it was driving from Monterey to Santa Cruz or Santa Cruz to SF that was pretty nice though
Lots of green trees
Christopher McCormack
@cmccormack
Aug 08 2018 21:47
You never realize how big this place is until you do a road trip between states
unless you live in the North East I guess
Simon Cordova
@gbsimon87
Aug 08 2018 22:18
Toronto is inside a province named Ontario, you can drive 14 hours north and you're still in Ontario
Brad
@bradtaniguchi
Aug 08 2018 22:26
Hell ya, I'm setting up forced best practices down everyones throat on this project muhahaha
Christopher McCormack
@cmccormack
Aug 08 2018 22:48
@bradtaniguchi man you are certainly excited about this refactor
Brad
@bradtaniguchi
Aug 08 2018 22:48
Yes, yes I am
newmoon
@newmoon
Aug 08 2018 23:12
I'm starting to study React, and maybe this is a stupid question...but why is there a specific React Bootstrap JS Library? Why wouldn't we just use standard Bootstrap css + js and use React to generate compatible HTML?