These are chat archives for FreeCodeCamp/HelpJavaScript

30th
Jan 2019
Brad
@bradtaniguchi
Jan 30 00:02
post your question, someone will help if they can
Idowu Wasiu
@Hoxtygen
Jan 30 00:03

I'm tasked with building a mock e-voting app... I'm a bit confused in one thing

The content of the database must be

{
“id” : Integer ,
“createdOn” : Date ,
“createdBy” : Integer , // represents the voter’s id
“office” : Integer , // represents the office being voted for
“candidate” : Integer , // represents the candidate

}

but the post request goes thus

{
“status” : Integer ,
“data” : {
“office” : Integer , // office unique id
“candidate” : Integer , // politician unique id
“voter” : Integer // voter unique id
}
}

The problem is how do I map voter in the post request to createdby in the database?

@bradtaniguchi was typing and doing some copy and paste
Brad
@bradtaniguchi
Jan 30 00:04
@Hoxtygen So what issue are you having with this exactly? Not sure where your having an issue besides knowing what your trying todo
Idowu Wasiu
@Hoxtygen
Jan 30 00:06
@bradtaniguchi there's no column in the database for voter in the post request, but there's a createdBy column which saves the voter Id, I don't know how to go about making the voterId in post request saves to createdBy column in the database since they have differnt names
Brad
@bradtaniguchi
Jan 30 00:07
@Hoxtygen Who not change the post data to the data required by the database? That's usually the servers job to manipulate the incoming data (among other thigns)
Idowu Wasiu
@Hoxtygen
Jan 30 00:08
@bradtaniguchi i was given a specification to work with, cant change it
Brad
@bradtaniguchi
Jan 30 00:08
How can you work with it? Where are "you" exactly in this problem?
(sorry if thats part of the challenge, i haven't done it)
Idowu Wasiu
@Hoxtygen
Jan 30 00:10
@bradtaniguchi I'm at the part where I have to make voterId in the post request store in the createdBy colum in the database
Brad
@bradtaniguchi
Jan 30 00:11
I'm confused, will you be building the server code that gets the post data in the spec? That will need to save this data to the database?
Idowu Wasiu
@Hoxtygen
Jan 30 00:11
@bradtaniguchi ys
Brad
@bradtaniguchi
Jan 30 00:11
Again, idk the actual challenge so I don't know the exact requirements at this time
Idowu Wasiu
@Hoxtygen
Jan 30 00:12
@bradtaniguchi yes i'm buildin the server
Brad
@bradtaniguchi
Jan 30 00:12
Ok yea, you will be building the server then, which as I mentioned earlier, it's your job to manipulate the data coming in, (from the post request) to a new object to save to the database with the required fields and format (the database format in the spec)
Jason Luboff
@JLuboff
Jan 30 00:13

@bradtaniguchi Hey...which solution do you like better..and why
First... two for loops.. (return occurs after the loops)

    for (let i = 0; i < hazards.length; i++) {
      hazards[i].checked = false;
      for (let j = 0; j < hazardAndControls.length; j++) {
        if (Object.keys(hazards[i])[0] === hazardAndControls[j].hazardID) {
          hazards[i].checked = true;
        }
      }
    }

Or two.. map + findIndex?

return hazards.map(hazard => {
      hazard.checked =
        hazardAndControls.findIndex(
          ({ hazardID }) => Object.keys(hazard)[0] === hazardID
        ) !== -1;
      return hazard;
    });
Idowu Wasiu
@Hoxtygen
Jan 30 00:14
@bradtaniguchi And I don't know how to go about that single problem i mentioned. And I'm using postgreql
@JLuboff option B
Brad
@bradtaniguchi
Jan 30 00:15
I see, the issue is you don't know who the createdBy is from the request right?
@JLuboff I don't like either, its like 6 lines of code but is very dense. Between the two it looks like the second is more performant, I dislike the idea of toggling flags on and off in double loops regardless tho
Kaz Baig
@kbaig
Jan 30 00:17
@JLuboff would Array.find be more useful for the second solution than findIndex?
Jason Luboff
@JLuboff
Jan 30 00:18
@bradtaniguchi I was learning towards the second one (its the refactor heh). Not positive I can get it to be a single loop... but.. I'll try and see
Idowu Wasiu
@Hoxtygen
Jan 30 00:18
@bradtaniguchi Actually the createdBy will store the id of the voter in the database, however, in the post request, the voterId is stored stored in the variable voter. Now how do I make createdBy in the database store the value in the voter variable from the post request?
Jason Luboff
@JLuboff
Jan 30 00:18
@kbaig Hmm I thought about that, but it'd basically be the same thing except I'd be checking if I get a result back
Kaz Baig
@kbaig
Jan 30 00:19
idk it just makes more semantic sense to me but it's not really that important
Brad
@bradtaniguchi
Jan 30 00:19
I'm not saying its possible with a single loop, but like code like this Object.keys(hazard)[0] seems very dangerous
Jason Luboff
@JLuboff
Jan 30 00:22

@bradtaniguchi this is a short bit of what hazards would look like

[
  {
    "1": "Back Strain",
    "checked": false
  },
  {
    "2": "Caught Between (Line of Fire)",
    "checked": false
  },
]

So I guess I could restructure that to be more like

{hazard : "Back Strain",
hazardID: 1,
checked: false
}

In which case I'd be able to get rid of the particular bit and instead use hazard.hazardID

Kaz Baig
@kbaig
Jan 30 00:23
I think that would make more sense
Brad
@bradtaniguchi
Jan 30 00:24

My issue with this Object.keys(hazard)[0] is the keys aren't required to be ordered so if your object is:

{1:'one', 2: 'two'}

you could end up with:
[2, 1]after doing Object.keys(obj), where [0] would be 2, which might screw up your behavior

Jason Luboff
@JLuboff
Jan 30 00:24
Still would need map + find/findIndex though I think
@bradtaniguchi Thats a good point, hadn't thought of that
Kaz Baig
@kbaig
Jan 30 00:25
I'm not sure it makes sense to have the key be the id from a key-value standpoint anyways
Brad
@bradtaniguchi
Jan 30 00:25
^Yes
I'd go more verbose in this case, but then my viewpoint is that of a "new" developer jumping into the code and I'm pretty confused.
Jason Luboff
@JLuboff
Jan 30 00:27
Psh...screw your new developer :P
Kaz Baig
@kbaig
Jan 30 00:27
write a comment above the map call and be done with it :wink:
Jason Luboff
@JLuboff
Jan 30 00:28
I have been getting into the habit of doing that as I've found myself forgetting what code is doing when I go back to it lol
Kaz Baig
@kbaig
Jan 30 00:28
I think it's good practice
In React, I tend to have comments above my methods for classes and that usually serves me well
Like when I was doing my own form validation
which I'm so glad I don't do anymore lol
Jason Luboff
@JLuboff
Jan 30 00:32
Ya thats what I do with React
Pagnito
@Pagnito
Jan 30 00:52
if i run redis is a seperate docker container does it effect performance?
Brad
@bradtaniguchi
Jan 30 01:07
@Pagnito Yes, but only a tiny bit. I wouldn't care about optimizing to that level
Pagnito
@Pagnito
Jan 30 01:11
@bradtaniguchi k sweet, thats the answer was hoping for
Tom
@moT01
Jan 30 01:19
Screen Shot 2019-01-29 at 7.19.09 PM.png
Kaz Baig
@kbaig
Jan 30 01:21
yep feels bad
Tom
@moT01
Jan 30 01:23
:poop:
yup
Brad
@bradtaniguchi
Jan 30 01:28
image.png
We are spoiled :P
Tom
@moT01
Jan 30 01:32
:poop:
Pagnito
@Pagnito
Jan 30 01:53
hey im having a problem with redis
im saving some values in one document, but tryin to get em in another but returning undefined
Brad
@bradtaniguchi
Jan 30 02:12
@Pagnito No experience with redis, not sure what a document is in this context tho, you sure you have it hooked up right?
Pagnito
@Pagnito
Jan 30 02:17
got it to work but cant seem to parse it
oh nvm, wasnt parsing it right
Riadh
@KWFE
Jan 30 03:17
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var val = {
    "alpha":"Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank"
  };
console.log(result)
  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("charlie");
well don't know why its not working
console.log(result) doesn't give back any returns
koshenzero
@koshenzero
Jan 30 03:59
@KWFE : result didn't assign value
Pagnito
@Pagnito
Jan 30 04:35
hey is there a way to records the userMedia stream from browser api straight to device
Nitin
@thenm
Jan 30 05:31

Here is the data

var obj = {
    "data_1_1_1": [
        [
            "firstname",
            "lastname",
            "mobileno",
            "EmailAddress",
            "UserID",
            "CreatedDate",
            "LoyaltyCash",
            "IsApproved"
        ],
        [
            "Rakesh",
            "Nimbalkar",
            "234252524",
            "rakesh@fc.com",
            "21924",
            "2011-07-13 15:25:25.273",
            "2.00",
            "False"
        ],
        [
            "Nitin",
            "Maul",
            "2343554364",
            "nitin@fc.com",
            "21924",
            "2011-07-13 15:25:25.273",
            "2.00",
            "False"
        ]
    ],
    "data_1_1_2": [
        [
            "PurchaseChanel"
        ],
        [
            "Online"
        ]
    ],
    "data_1_1_3": [
        [
            "RowNum",
            "createdDate"
        ],
        [
            "1",
            "2018-06-20 12:03:03.350"
        ]
    ]
}

I want to convert it to

 {
    data_1_1_1: [ 
         {
            firstname: "Rakesh",
            lastname: "Nimbalkar",
            mobileno: "2342345342",
            EmailAddress: "rakesh@fy.com",
            UserID: "21924",
            CreatedDate: "2011-07-13 15:25:25.273",
            LoyaltyCash: "2.00",
            IsApproved: "False"
        },
        {
            firstname: "Nitin",
            lastname: "Maul",
            mobileno: "2342345342",
            EmailAddress: "9552597782",
            UserID: "21924",
            CreatedDate: "2011-07-13 15:25:25.273",
            LoyaltyCash: "2.00",
            IsApproved: "False"
        }
    ],

    data_1_1_2: [
       {
         PurchaseChanel:"Online"
       }
    ],
    data_1_1_3: [
      {
         RowNum: "1",
         createdDate
      }
    ]
}

How Can I do that here i am trying to achieve the result https://jsbin.com/vevetok/edit?js,console

Kaz Baig
@kbaig
Jan 30 06:11
@thenm look at Array.slice, Array.map, and computed properties
tundeiness
@tundeiness
Jan 30 13:15
need help on this project https://codepen.io/highness/pen/xmMMoG?editors=0011 can someone help please?
Christopher McCormack
@cmccormack
Jan 30 15:36
@tundeiness don't use the CodePen console if you expect to get useful errors. Use the browser console instead, where you'll see the error TypeError: Cannot read property 'sounds' of undefined. This error means you called .sounds on an object that doesn't have a property sounds, which in this case is in your Drums component where you are trying to call this.props.state.sounds.map(...)
tundeiness
@tundeiness
Jan 30 15:37
@cmccormack okay
Christopher McCormack
@cmccormack
Jan 30 15:38
remove .state from that chain and then you have some syntax errors to fix as well
tundeiness
@tundeiness
Jan 30 15:38
@cmccormack alright
Christopher McCormack
@cmccormack
Jan 30 15:39
You also aren't actually passing sounds to Drums
tundeiness
@tundeiness
Jan 30 15:46
@cmccormack well that is where i am missing out
Christopher McCormack
@cmccormack
Jan 30 15:47
add sounds={this.state.sounds} as an attribute to Drums from the parent component
Drums will then have access to it via props
tundeiness
@tundeiness
Jan 30 15:47
@cmccormack eventually I am back to the idea I mooted earlier set sounds as a state.
Christopher McCormack
@cmccormack
Jan 30 15:48
I don't know what you mean by that so I can't really provide feedback
tundeiness
@tundeiness
Jan 30 15:51
@cmccormack initially my thoughts was to set up the sound attribute in the parent component and from there let it trickle down to the child class but that got me confused on the issue of when drum-pads are clicked how do they access the data
Christopher McCormack
@cmccormack
Jan 30 15:52
@tundeiness who is they?
do you know of the ref attribute?
tundeiness
@tundeiness
Jan 30 15:53
@cmccormack :laughing: the drum component and other components
tundeiness
@tundeiness
Jan 30 15:54
@cmccormack yes I have seen it here and there but FCC didn't include it in their syllabus
Christopher McCormack
@cmccormack
Jan 30 16:00
I feel like this project either wants you to use refs or use vanilla javascript to grab the element directly. I chose the former because it's cleaner but you can use the latter as well
either way, all you need for the child to do is pass to its callback the button that was clicked, in some way - whether it be the id or the letter or whatever, and you can then parse that in your handler function to determine what to do with it
Jason Luboff
@JLuboff
Jan 30 16:10
morning
Kaz Baig
@kbaig
Jan 30 16:11
:wave:
how do you do jason
Christopher McCormack
@cmccormack
Jan 30 16:12
Heya
Jason Luboff
@JLuboff
Jan 30 16:12
Doing alright...how are you guys?
Kaz Baig
@kbaig
Jan 30 16:12
Good man. Got done editing those videos and feeling the burnout but also feeling good :smile:
Gonna get back to my portfolio today hopefully
Jason Luboff
@JLuboff
Jan 30 16:14
Nice man
Christopher McCormack
@cmccormack
Jan 30 16:14
Good man no idea what I"m doing today
hoping to work a little on some git aliases for bash
Jason Luboff
@JLuboff
Jan 30 16:15
Think I'm going to start the day with working on some backend database stuff before going back to the react side of things
Christopher McCormack
@cmccormack
Jan 30 16:15
nice
Have you guys ever come across any good documentation about how to lay out your REST endpoints? Like the best endpoint structure to use for login/register/etc...?
Kaz Baig
@kbaig
Jan 30 16:16
Nah as far as I understand it, it's mostly up to you
Christopher McCormack
@cmccormack
Jan 30 16:16
Like POST to /api/login to create session, DELETE to remove it, etc...
Kaz Baig
@kbaig
Jan 30 16:16
So long as it makes sense
Kaz Baig
@kbaig
Jan 30 16:16
there's some best practices ^
Jason Luboff
@JLuboff
Jan 30 16:16
Those are two pages I still need to read through but sort of touches on that
Kaz Baig
@kbaig
Jan 30 16:17
but not really any rules
My old company's user facing api builder would treat post and get requests the same way
and not accept any other verb
Christopher McCormack
@cmccormack
Jan 30 16:17
Yeah but they aren't specific to different commonly used actions, that's what I'm really looking for
GET is bad
Kaz Baig
@kbaig
Jan 30 16:18
what's bad about GET?
Christopher McCormack
@cmccormack
Jan 30 16:18
if it does the same as post
Kaz Baig
@kbaig
Jan 30 16:18
oh yeah
it was the other way around though, POST was treated as GET
Christopher McCormack
@cmccormack
Jan 30 16:18
you can embed the url into an image and email it to someone and boom they've basically posted something to your api
Kaz Baig
@kbaig
Jan 30 16:18
this was bad practice
Christopher McCormack
@cmccormack
Jan 30 16:18
oh that's not so bad
dumb, but not necessarily destructive
Kaz Baig
@kbaig
Jan 30 16:18
ye
Christopher McCormack
@cmccormack
Jan 30 16:19
unless the GET modifies as well lol
Jason Luboff
@JLuboff
Jan 30 16:19
I attach GET and POST to the same route but they obiviousily do different things
Kaz Baig
@kbaig
Jan 30 16:19
it can, just depends on what your mathematica code for that endpoint does

I attach GET and POST to the same route but they obiviousily do different things

same

GET /poll/:id
POST /poll/<poll attributes>
Christopher McCormack
@cmccormack
Jan 30 16:21
I was really hoping there was some excellent table somewhere that shows best practices for stuff like user auth/registration/etc... so I could build the rest of my api in a similar fashion
I read several best practices last night and they were helpful but still left me wondering how a large company that really has their shit together would do it
Kaz Baig
@kbaig
Jan 30 16:23
Yeah it would be helpful to know that...
maybe @bradtaniguchi can help
Christopher McCormack
@cmccormack
Jan 30 16:30
figure he would just pop in when mentioned, guess not lol
Jason Luboff
@JLuboff
Jan 30 16:32
I don't think he usually is on until around 11
Jason Luboff
@JLuboff
Jan 30 16:38
Do you guys ever have a realization late at night about some process you're trying to implement and go "OH... why the fuck was I overcomplicating this?"
Kaz Baig
@kbaig
Jan 30 16:39
allll the time
Jason Luboff
@JLuboff
Jan 30 16:40
I have been debating for a week how to design my database based on conditions that have changed... only to realize this morning... I'm way overcomplicating the way I was thinking about it.
Christopher McCormack
@cmccormack
Jan 30 16:58
@JLuboff i've found creating a UML diagram for certain flows really helps me determine the best way to design something, it kind of forces you to cover all your bases
Jason Luboff
@JLuboff
Jan 30 17:00
I had actually drawn out my original design based on user requirements but...those requirements changed
But....my original design mostly still adheres
Kevin Peña
@kebien6020
Jan 30 17:46
@thenm This seems to work. (Results in the dev console)
Brad
@bradtaniguchi
Jan 30 18:15
@kbaig hullo wut
Hmm ok I just caught up with the discussion, and yea don't expect me until like 10:00 :p
But idk if I have the best background since I'm at a small company (that questionably has their shit together) hehehe
Jason Luboff
@JLuboff
Jan 30 18:19
10... 11.... same difference heh
Brad
@bradtaniguchi
Jan 30 18:21
I should tell that to my boss :P
Jason Luboff
@JLuboff
Jan 30 18:22
Do it
See what he says heh
Brad
@bradtaniguchi
Jan 30 18:25
@JLuboff He usually rolls in around 10:30-11:00 on a normal day anyways XD
Jason Luboff
@JLuboff
Jan 30 18:28
How lazy :P
Brad
@bradtaniguchi
Jan 30 18:32
Possibly hehe
// the global Array
var s = [23, 65, 98, 5];

Array.prototype.myMap = function(callback){
  var newArray = [];
  // Add your code below this line
  for(let i=0; i<this.length; i++) {
    newArray.push(this[i]*2);
  }
  // Add your code above this line
  return newArray;

};

var new_s = s.myMap(function(item){
  return item * 2;
});

console.log(new_s)
I think this is not the proper answer :D
Christopher McCormack
@cmccormack
Jan 30 18:34
nope
enestatli
@enestatli
Jan 30 18:35
but it passes the test
Christopher McCormack
@cmccormack
Jan 30 18:35
why are you doing the math in your prototype function
let your callback do that
enestatli
@enestatli
Jan 30 18:35
I need to use callback thing but do not know how
Christopher McCormack
@cmccormack
Jan 30 18:35
nowhere in your function do you use your callback
enestatli
@enestatli
Jan 30 18:35
hmm
callback(this[i])
@cmccormack it works but do not know why excatly
Christopher McCormack
@cmccormack
Jan 30 18:37
how what works?
enestatli
@enestatli
Jan 30 18:37
callback thing
it is just an argument
Jason Luboff
@JLuboff
Jan 30 18:38
a callback is just a function thats passed into another function
Christopher McCormack
@cmccormack
Jan 30 18:38
var new_s = s.myMap(function(item){
  return item * 2;
});
when you pass that anonymous function to your myMap, it's stored as callback
enestatli
@enestatli
Jan 30 18:39
item * 2;
Christopher McCormack
@cmccormack
Jan 30 18:39
so callback === function(item){ return item * 2; }
enestatli
@enestatli
Jan 30 18:39
ohhh
I completely understand :D
Christopher McCormack
@cmccormack
Jan 30 18:39
nice!
enestatli
@enestatli
Jan 30 18:40
@cmccormack @JLuboff thank you!
Christopher McCormack
@cmccormack
Jan 30 18:40
honestly it took me a while to fully comprehend callback in a way that stuck
May Kittens Devour Your Soul
@diomed
Jan 30 18:40
hello guys
anyone from Chicago?
Brad
@bradtaniguchi
Jan 30 18:40
@enestatli functions (the callback variable in this case) are just like any other variable in JS, except you can "run them"
Christopher McCormack
@cmccormack
Jan 30 18:40
@diomed the :cat: is back!
@diomed I believe @kbaig is nearby
Jason Luboff
@JLuboff
Jan 30 18:40
It also took me a long time to understand callbacks...don't think I really got it until I started working in node...
Riadh
@KWFE
Jan 30 18:41
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookup = val;

  val = {
    "alpha":"Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank"
  };

  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("charlie");
Christopher McCormack
@cmccormack
Jan 30 18:42
@JLuboff yeah, Node did help. It's not like they are that complicated, but JavaScript is the first language I've used that tosses them around like candy
May Kittens Devour Your Soul
@diomed
Jan 30 18:42
@kbaig you alive bro?
I've read they have extreme conditions
Jason Luboff
@JLuboff
Jan 30 18:43
@cmccormack Ya I can't quite remember with C# but...I don't think it uses callbacks
May Kittens Devour Your Soul
@diomed
Jan 30 18:43
like -40 degrees
@ night
enestatli
@enestatli
Jan 30 18:43
@bradtaniguchi so in short, callback functions are ready to run variables
Christopher McCormack
@cmccormack
Jan 30 18:43
in Python they have lambda functions which are close
but most work is synchronous in these languages so you don't really need it as often
@KWFE hey bud if you're going to post code you should try to keep it at a minimum, else use external tools like CodePen or repl.it
enestatli
@enestatli
Jan 30 18:44
@cmccormack oh this makes me sad :D
Riadh
@KWFE
Jan 30 18:45
ok
Brad
@bradtaniguchi
Jan 30 18:45
@enestatli Yea, like you can try to run other variables, but will get an error. functions are "special" in that case. But like other variables you can still do stuff like this:
const var1 = () => {} // arrow functions are the same as other functions, for the most part
var1 === var1; // true
Christopher McCormack
@cmccormack
Jan 30 18:45
@enestatli think of a callback function as basically passing a value to a function, but that value is the reference to a function instead of the actual value
Brad
@bradtaniguchi
Jan 30 18:46
But yea, the idea of a callback tripped me up for a while, but the idea of "runable variables" made the callback idea simpler to digest.
It actually blew my mind, since I came from a Java background haha
@KWFE What have you found that is wrong with your code, have you console.log anything interesting at any point in the code? How much have you "worked the problem"
May Kittens Devour Your Soul
@diomed
Jan 30 18:49
@cmccormack
_ A _
A _ _ _ _
_ _ M _ _ _ _ W
Christopher McCormack
@cmccormack
Jan 30 18:50
@diomed C as Crepuscular
May Kittens Devour Your Soul
@diomed
Jan 30 18:50
no C
Brad
@bradtaniguchi
Jan 30 18:51
t
May Kittens Devour Your Soul
@diomed
Jan 30 18:51
_ A _
A _ T _ _
T _ M _ _ _ _ W
Christopher McCormack
@cmccormack
Jan 30 18:51
DAY AFTER TOMORROW
May Kittens Devour Your Soul
@diomed
Jan 30 18:51

OH COME ON!

Brad
@bradtaniguchi
Jan 30 18:51
^ :+1:
May Kittens Devour Your Soul
@diomed
Jan 30 18:51
how the heck?
Christopher McCormack
@cmccormack
Jan 30 18:52
Last word looks like tomorrow already :)
Brad
@bradtaniguchi
Jan 30 18:52
Yea, I can't really thing of what else it could be haha
May Kittens Devour Your Soul
@diomed
Jan 30 18:52
@bradtaniguchi he's spying me, I tell ya. ever since he made me app he's guessing them all so fast
Christopher McCormack
@cmccormack
Jan 30 18:52
Wheel was my favorite game show as a kid
May Kittens Devour Your Soul
@diomed
Jan 30 18:53
Chicago - Day after tomorrow
Christopher McCormack
@cmccormack
Jan 30 18:54
My scariest flight was a routine flight into Chicago once
they do this crazy bank to get around a mountain or something, and it's very windy
May Kittens Devour Your Soul
@diomed
Jan 30 18:57
_ _ _ D
_ _ T _
_ _ P _ _ _ _
_ _ D
_ T _ _
Brad
@bradtaniguchi
Jan 30 19:00
I wanna buy an e
Christopher McCormack
@cmccormack
Jan 30 19:01
S
no vowels this early @bradtaniguchi
Brad
@bradtaniguchi
Jan 30 19:01
damn, I didn't watch enough of wheel of fortune :P, I was more a price is right guy hehe
May Kittens Devour Your Soul
@diomed
Jan 30 19:03
_ _ _ D
_ _ T _
_ _ P _ E S S
_ _ D
S T _ _
Kevin Peña
@kebien6020
Jan 30 19:04

If you come from Java you can think of the function expecting a callback to be passed as a method expecting a Runnable to be passed, in java you use the runnable as someRunnable.run(), whereas in JS it is just callback(). The way you pass it to the function in java is something like

myMethod(new Runnable() {
  public void run() {
    // some code here
  }
});

and in JS

myFunc(function() {
  // some code here
});
// or mostly equivalent
myFunc(() => { /* some code here */ });
Christopher McCormack
@cmccormack
Jan 30 19:04
L
May Kittens Devour Your Soul
@diomed
Jan 30 19:05
nuLL
Christopher McCormack
@cmccormack
Jan 30 19:05
N
May Kittens Devour Your Soul
@diomed
Jan 30 19:06
@kebien6020 take a break, have a guess
1Ne
_ _ _ D
_ _ T _
_ _ P _ E S S
_ N D
S T _ _
Christopher McCormack
@cmccormack
Jan 30 19:07
R is in Rascal
May Kittens Devour Your Soul
@diomed
Jan 30 19:07
always a good letter
R _ _ D
_ _ T _
_ _ P R E S S
_ N D
S T _ R
gotta find some words with no R
Riadh
@KWFE
Jan 30 19:08
@bradtaniguchi am i on the right path?
Brad
@bradtaniguchi
Jan 30 19:08
@KWFE I should be asking you what you think
Kevin Peña
@kebien6020
Jan 30 19:09
A
Christopher McCormack
@cmccormack
Jan 30 19:09
X
7
May Kittens Devour Your Soul
@diomed
Jan 30 19:09
why did no1 tell me I'm in the wrong help room :P
Christopher McCormack
@cmccormack
Jan 30 19:09
/shrug
it's been quiet in there without you
May Kittens Devour Your Soul
@diomed
Jan 30 19:10
R _ A D
_ _ T _
_ _ P R E S S
A N D
S T A R
Riadh
@KWFE
Jan 30 19:10
i think i must create an object lookup it should look like this
Christopher McCormack
@cmccormack
Jan 30 19:10
M
Riadh
@KWFE
Jan 30 19:10
var lookup = {
code here
};
May Kittens Devour Your Soul
@diomed
Jan 30 19:10
noM
Riadh
@KWFE
Jan 30 19:11
and i must to assign the object to the variable result
Christopher McCormack
@cmccormack
Jan 30 19:12
C
ROAD WITH CYPRESS AND STAR
May Kittens Devour Your Soul
@diomed
Jan 30 19:13
BAM :zap: You know it :congratulations: :star: :stars: @cmccormack
Christopher McCormack
@cmccormack
Jan 30 19:13
That middle word was killing me
May Kittens Devour Your Soul
@diomed
Jan 30 19:13
nice word :)
my apologies. this all should have happened in general Help room. :stuck_out_tongue:
Kevin Peña
@kebien6020
Jan 30 19:14
@KWFE Read the MDN page on property accessors Especially the section about bracket notation.
Brad
@bradtaniguchi
Jan 30 19:14
@KWFE Thats not valid js, you can't put code in the object
^
Riadh
@KWFE
Jan 30 19:15
@bradtaniguchi yes i mean the same list i posted before christopher says that i must make the code shorter
Christopher McCormack
@cmccormack
Jan 30 19:17
@KWFE you posted your code twice, one duplicated, I deleted the duplicate, and suggested if you're going to post anything larger do it on an external site and provide us the link to review
Sites like Codepen are nice as we can fork it, play with it, and provide better help
and we can also see your updates when you save
May Kittens Devour Your Soul
@diomed
Jan 30 19:18
jsbin
Christopher McCormack
@cmccormack
Jan 30 19:19
you should make your own @diomed called Cat Scratch
Riadh
@KWFE
Jan 30 19:19
@cmccormack u deleted the correct one
lol
its ok
Christopher McCormack
@cmccormack
Jan 30 19:24
Sorry @KWFE try to edit your post instead in the future
Kevin Peña
@kebien6020
Jan 30 19:30
@KWFE Actually, the main concept you need to grasp to solve this one is right here in your own repo
To use a lookup table you just need to access object properties using a variable
Christopher McCormack
@cmccormack
Jan 30 19:32
nice
Brad
@bradtaniguchi
Jan 30 19:33
Man Idk if these tests are haunted or I'm just missing something tiny...
whats really odd is I'm testing 1 function and its working, but when I call it from another the first function always returns true even tho the tests on the first one shows it doesnt....
omg...
Kevin Peña
@kebien6020
Jan 30 19:38
does it depend on global state?
Brad
@bradtaniguchi
Jan 30 19:38

"passing" test:

{
  // id: 'blah',
  name: 'name'
}

"failing" test:

{
  id: undefined,
  name: 'name'
}
Object.keys(obj) doesn't care about the id being undefined -___-
(╯°□°)╯︵ ┻━┻
Kevin Peña
@kebien6020
Jan 30 19:41
It works fine for me in chrome devtools
image.png
Brad
@bradtaniguchi
Jan 30 19:41
Yea my code didn't expect that and wanted the reverse behavior, I was just dumb
Idk if it would even be possible to get an object with "undefined" as the value, but have the key if the object came from a post request :/
Kevin Peña
@kebien6020
Jan 30 19:43
It seems to be consistent with other ways of checking existence of a key
image.png
Brad
@bradtaniguchi
Jan 30 19:44
@kebien6020 Yes, it is, but I was using it to check for key+value, which is incorrect. My other test cases which were always working had tests that never specified the key what so ever
Riadh
@KWFE
Jan 30 19:48
really don't understand what do you mean
Kevin Peña
@kebien6020
Jan 30 19:48
Yeah, a short way of expressing this would be Boolean(obj.id), which returns false if the object doesn't have the key and also false if it is undefined, this approach only works if 0, false and null are never valid values for obj.id.
Otherwise maybe objKeys.indexOf('id') !== -1 && obj.id !== undefined
Brad
@bradtaniguchi
Jan 30 19:51
welp I end up with like 15 more test-cases re-testing the same code, oh wellz haha
Jason Luboff
@JLuboff
Jan 30 20:16

@cmccormack ...are you a chat mod now..?

you posted your code twice, one duplicated, I deleted the duplicate, and suggested if you're going to post anything larger do it on an external site and provide us the link to review

Christopher McCormack
@cmccormack
Jan 30 20:17
@JLuboff yeah, part of becoming a moderator
Jason Luboff
@JLuboff
Jan 30 20:18
Hear that everybody? @cmccormack is a narc!
Christopher McCormack
@cmccormack
Jan 30 20:18
haha I was TRYING not to make that public
Jason Luboff
@JLuboff
Jan 30 20:18
Well you didn't try very hard considering you said you deleted another users post lol
Christopher McCormack
@cmccormack
Jan 30 20:19
yeah good point
Kaz Baig
@kbaig
Jan 30 20:19
@diomed yeah im gucci
Christopher McCormack
@cmccormack
Jan 30 20:19
eagle eyes
Jason Luboff
@JLuboff
Jan 30 20:19
;)
@kbaig So have you gone outside?
Kaz Baig
@kbaig
Jan 30 20:19
heeeell no
I'm not interested in dying today
Jason Luboff
@JLuboff
Jan 30 20:20
Not even to just feel what its like to be in -60* weather? (or atleast I heard in some areas with the wind chill its that cold)
Kaz Baig
@kbaig
Jan 30 20:21
Right out my window, there's a vent that blows hot air and that air looks like a blizzard unto itself right now
so noooo thanks
Jason Luboff
@JLuboff
Jan 30 20:22
I dunno..I think I would want to atleasst just step outside to feel whats its like and run back inside heh
react animated burgers trending on reddit
Brad
@bradtaniguchi
Jan 30 20:33
I think the coldest I've ever experienced was like 30, so i'm totally clueless as to how negative degrees feel haha
Kevin Peña
@kebien6020
Jan 30 20:38
well 30 °F are negative in Celsius so technically...
Christopher McCormack
@cmccormack
Jan 30 20:59
@kbaig those are pretty nice
lol I want to start using hombre pages to learn about my commands - https://github.com/freeCodeCamp/freeCodeCamp/pull/22143/files
Brad
@bradtaniguchi
Jan 30 21:03
@cmccormack lol, well at least it wasn't translated wrong, its just hehe
Christopher McCormack
@cmccormack
Jan 30 21:04
can get lots of PRs approved by just google translating some of these guides I bet lol
Brad
@bradtaniguchi
Jan 30 21:07
Haha makes sense, I still need to look into contributing to FCC :/
Kevin Peña
@kebien6020
Jan 30 22:01
Well manual in spanish is manual, so you could argue its actually translated wrong
Jeff
@jargonfilter
Jan 30 22:10

hey everyone. i just finished this exercise on fcc: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin/

what do you think of my solution? i'm guessing its not the best way of doing this lol

function translatePigLatin(str) {

  let strArr = str.split(/^([^aeiou]*)/).filter(x=>x);
  /[aeiou]/.test(strArr[0]) ? strArr.push("way") : strArr.push(strArr.splice(0,1) + "ay"); 
  return strArr.join('');
}

translatePigLatin("algorithm");
Brad
@bradtaniguchi
Jan 30 22:12
@jargonfilter That second line looks funky, you only need to check the first one in the string? (I forgot how the challenge works), Do you need that .filtercall? I don't think you need letit could be const right?
Jeff
@jargonfilter
Jan 30 22:18
i added the filter just cause i noticed it was giving me an empty string
at the beginning
like
"", "gl" "ove"
the filter got rid of that empty string
since i wanted to test the first element it seemed like something i ought to do
and filter seemed to work heh
const seems to work instead of let.
Christopher McCormack
@cmccormack
Jan 30 22:20
I do that sometimes too, it's my filter tank (filter(_=>_))
Jeff
@jargonfilter
Jan 30 22:20
ah wasnt sure if i needed the x there or not
Christopher McCormack
@cmccormack
Jan 30 22:21
it's whatever you want
that is a valid variable name
I just like the underscore because it looks like a tank to me :)
Jeff
@jargonfilter
Jan 30 22:21
yeah i actually thought you had empty spaces there for a second lol
Brad
@bradtaniguchi
Jan 30 22:22
@cmccormack haha filter tank XD
Christopher McCormack
@cmccormack
Jan 30 22:22
It rolls over the array squishing all the empty indexes!
Jeff
@jargonfilter
Jan 30 22:23
does my 2nd line still look funky then
Christopher McCormack
@cmccormack
Jan 30 22:24
why split it?
Sorry I was only commenting on the filter tank lol
Jeff
@jargonfilter
Jan 30 22:24
heh
why split it? i dont know it just seemed like the easiest way for my head to wrap around it lol
i guess i could just do the whole thing with the 2nd line then
Christopher McCormack
@cmccormack
Jan 30 22:26
I would
Pagnito
@Pagnito
Jan 30 22:57
does html not have an input type for incrementing or decrementing a value?
Brad
@bradtaniguchi
Jan 30 22:57
@Pagnito type="number"
will add an arrow to the side todo just that
and only allow number inputs too, all this is done in browser
Pagnito
@Pagnito
Jan 30 22:58
@bradtaniguchi yes!
@bradtaniguchi sweet thnx
Brad
@bradtaniguchi
Jan 30 22:58
np :D
Christopher McCormack
@cmccormack
Jan 30 23:20
@bradtaniguchi you do docker stuff sometimes right?
Brad
@bradtaniguchi
Jan 30 23:26
On a little, I wouldn't say I was very successful with it tho haha @cmccormack
Christopher McCormack
@cmccormack
Jan 30 23:26
I wanted to spin up a tiny debian image to do some testing on, would Docker be good for this?
or would it be better to create a VM and use snapshots?
Brad
@bradtaniguchi
Jan 30 23:27
Id say it depends on what exactly your testing in it, smaller docker the better
@cmccormack so what will you be testing in the image exactly?
Christopher McCormack
@cmccormack
Jan 30 23:30
just want a clean slate for testing out my dotfiles repo, all my aliases and functions, etc...
something I can reset quickly
Brad
@bradtaniguchi
Jan 30 23:31
what does that repo do exactly? (im gonna look it up right now too)
Christopher McCormack
@cmccormack
Jan 30 23:31
it's all my .bashrc, .bash_profile, etc... files
also starting to include my vs code configs and other stuff
this way I can just clone the repo to any new system, run a shell script to copy it to my home directory, then source my .bash_profile along with any other stuff
hmm I guess if I just load a new shell it should be like new shouldn't it
Brad
@bradtaniguchi
Jan 30 23:33
Ah I see, well I think you can try it out. It would be faster/less overhead than a VM, and I think it would work out fine if you picka robust image
@cmccormack If you load a new shell, and you replaced the .bashrc/stuff then it wouldn't work, but if you have to manually load the stuff (using source) you could test it that way too
It doesn't look like your doing anything crazy in the dotfiles so I don't see why it wouldn't work with a docker-image. But the devils in the details I've found with Docker :/
Christopher McCormack
@cmccormack
Jan 30 23:35
honestly if it didn't work in the docker container I would work to make it work
the idea is to have one config that works on mac and linux
that all assumes uname is on all of those but I think it's POSIX compatable
I may try to include some powershell stuff later
powershell has some neat tools now
Brad
@bradtaniguchi
Jan 30 23:36
oh gosh powershell...
Christopher McCormack
@cmccormack
Jan 30 23:38
it has scoop which is pretty neat
I was able to get some nice git integration in powershell
Now what I really want is to be able to use zsh with git for windows
Brad
@bradtaniguchi
Jan 30 23:44
Id have to try really really hard to start enjoying developing on windows
(really)
on a side-note I added a feature and 80 tests broke somewhere else :'D
Christopher McCormack
@cmccormack
Jan 30 23:45
I just needed to get to a place where I could work on the fcc repo locally without the huge slowdown that WSL introduces
@bradtaniguchi uh oh sounds like something is too tightly coupled
Brad
@bradtaniguchi
Jan 30 23:45
actually take it back I did add 1 line, changed a function so I'm not calling a stub hehe
Jason Luboff
@JLuboff
Jan 30 23:46
I'm trying to figure out why my damn post route test won't work. Keeps timing out
Brad
@bradtaniguchi
Jan 30 23:47
@JLuboff Is it the correct URL? (gets me every time)
Christopher McCormack
@cmccormack
Jan 30 23:47
@JLuboff do you have a middleware that shows your backend is getting it?
Jason Luboff
@JLuboff
Jan 30 23:48
Ya... I added in a console.log and see the returned response
Christopher McCormack
@cmccormack
Jan 30 23:48
const logger = require('morgan')
app.use(logger('dev'))
if you see the returned response isn't it working?
Jason Luboff
@JLuboff
Jan 30 23:49
No.. it times out... doesn't make sense. I have another test going to the exact same route which works...
Christopher McCormack
@cmccormack
Jan 30 23:49
do you have a catch?
Jason Luboff
@JLuboff
Jan 30 23:50
I'm sending slightly different data.....maybe its something goofy there but I'd expect an error to be thrown.
Ya I do
Christopher McCormack
@cmccormack
Jan 30 23:51
how exactly do you see the returned response?
Jason Luboff
@JLuboff
Jan 30 23:53
console.log(`RES: ${JSON.stringify(res, null, 2)}`);

Which is below

const res = await request(app).post('/newJSA').send(postData);

but above my expect. Hell I can have no expect and still timesout... but the test above which use the same route and same const res..(scoped to its own test) works fine

Christopher McCormack
@cmccormack
Jan 30 23:55
did you pass done ?
also I have no idea what tools your using so I'm just throwing spaghetti against the wall
Jason Luboff
@JLuboff
Jan 30 23:56
shouldn't need to with async/await
jest + supertest :)
Christopher McCormack
@cmccormack
Jan 30 23:57
hmm I'm not sure, I've just barely used jest myself
so on that note I'm going to run my ignorant self away and make dinner :)
Jason Luboff
@JLuboff
Jan 30 23:57
Maybe I have an issue in my test post data...
Haha alright, enjoy
Christopher McCormack
@cmccormack
Jan 30 23:58
thanks