These are chat archives for FreeCodeCamp/HelpJavaScript

27th
Jun 2018
Christopher McCormack
@cmccormack
Jun 27 2018 00:45
@devbysalas try filling in some of the other letters that are in the test into your regex
Carlos Alfaro
@devbysalas
Jun 27 2018 00:56
okay I'm going to try @cmccormack
Thank you that worked @cmccormack
let ohStr = "Ohhh no";
let ohRegex = /Oh{3,6} no/; // Change this line
let result = ohRegex.test(ohStr);
Christopher McCormack
@cmccormack
Jun 27 2018 00:59
nice!
Bjorn van de Peut
@bjorno43
Jun 27 2018 01:04
@cmccormack Told ya I'd work on one: https://icecub.nl/ide/ :laughing:
Christopher McCormack
@cmccormack
Jun 27 2018 01:06
@bjorno43 isn't quite working for me
Bjorn van de Peut
@bjorno43
Jun 27 2018 01:06
It's not finished yet, but it should be functional. What's not working?
Christopher McCormack
@cmccormack
Jun 27 2018 01:07
I'll do some JS code, console.log maybe, then start doing some html and the console statement will appear in my output, I think it's an unclosed tag issue
looks really cool though! Did it take long to make?
Bjorn van de Peut
@bjorno43
Jun 27 2018 01:09
Nah, making it is pretty easy. Unfortunetely I'm unable to reproduce that problem
Christopher McCormack
@cmccormack
Jun 27 2018 01:11
start a new page, type a javascript console.log('something'), start typing html
Chrome, fwiw
Bjorn van de Peut
@bjorno43
Jun 27 2018 01:12
First you download some syntax highlighter library like ACE Editor or Codemirror. Then you simply create an iframe. Create a JS string with basic HTML structure and implement the users html inside the body tag, the css inside style tag and the js inside a script tag. Send it towards the iframe and you're done :P
Christopher McCormack
@cmccormack
Jun 27 2018 01:12
it's inconsistent, if you type the js then something like <div></div> in html then hit backspace seems to work more consistent
Bjorn van de Peut
@bjorno43
Jun 27 2018 01:13
Ah I've reproduced it
Christopher McCormack
@cmccormack
Jun 27 2018 01:13
not sure what you'd do about that though!
tons of closing tags? :D
Bjorn van de Peut
@bjorno43
Jun 27 2018 01:14
I'll have to find the cause first. It's only happening in Chrome. Not in Firefox
Christopher McCormack
@cmccormack
Jun 27 2018 01:14
or just parse it for every keystroke in a stack and fill in however many you need
Bjorn van de Peut
@bjorno43
Jun 27 2018 01:16
@cmccormack Should be fixed in Chrome now
Christopher McCormack
@cmccormack
Jun 27 2018 01:18
nope
Bjorn van de Peut
@bjorno43
Jun 27 2018 01:19
Odd. It's no longer happening here..
I've tried IE, Chrome and FF.. Can't reproduce it
Wait, now it finally happened..
Ah I see what happens. Hmm
Christopher McCormack
@cmccormack
Jun 27 2018 01:24
yay I'm not crazy
Bjorn van de Peut
@bjorno43
Jun 27 2018 01:25
Ghehe no. For some reason Chrome pushes the result towards the iframe even when syntax errors are present. It shouldn't do that
Basicly it does something like this <div<script> console.log('something') </script>></div>
So the script tag is ignored
Christopher McCormack
@cmccormack
Jun 27 2018 01:28
that makes sense you're closing an invalid element
<div<script>
Bjorn van de Peut
@bjorno43
Jun 27 2018 01:31

Ye but looking at the backend, it doesn't make sense. This is how the string is build:

'<body>'+ htmlEditor.getValue() +
    '<script type="text/javascript">'+ jsEditor.getValue() + '</scr'+'ipt>'+
'</body>'

Obviously it makes sense when htmlEditor.getValue() contains invalid code. But there's code in place that prevents that string from being build if htmlEditor.getValue() contains syntax errors..

Christopher McCormack
@cmccormack
Jun 27 2018 01:32
maybe it's an issue in your getValue function
no clue :)
why did you break up </script>?
Bjorn van de Peut
@bjorno43
Jun 27 2018 01:34
Because you can't use </script> inside a string in JS. Your browser picks that up as a valid end tag
Christopher McCormack
@cmccormack
Jun 27 2018 01:37
that's funny
@bjorno43 that's really cool though I like the look of it and hope to see the next iteration soon!
I gotta run for now i'll see you tomorrow hopefully
Bjorn van de Peut
@bjorno43
Jun 27 2018 01:39
@cmccormack Sure m8, cya around!
abraham anak agung
@padunk
Jun 27 2018 05:52

@bjorno43

@cmccormack Told ya I'd work on one: https://icecub.nl/ide/ :laughing:
nice, you using codemirror?

Bjorn van de Peut
@bjorno43
Jun 27 2018 07:27
@padunk No I've used ACE Editor for this one. But it'd just as easy with Codemirror
Shubham soni
@shubhamsoni2617
Jun 27 2018 08:32

Basic Data Structures: Iterate Through All an Array's Items Using For Loops
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-all-an-arrays-items-using-for-loops

function filteredArray(arr, elem) {
  let newArr = [];
  // change code below this line
for(let i=0;i<arr.length;i++){
if(arr[i].indexOf(elem)==-1){
  newArr.push(arr[i]);

  }
}
  // change code above this line
  return newArr;
}

// change code here to test different cases:
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));

The above code works.

function filteredArray(arr, elem) {
  let newArr = [];
  // change code below this line
for(let i=0;i<arr.length;i++){
  for(let j=0;j<arr[i].length;j++){
if(arr[i].indexOf(elem)==-1){
  newArr.push(arr[i]);
}
  }
}
  // change code above this line
  return newArr;
}

// change code here to test different cases:
console.log(filteredArray([ ["trumpets", 2], ["flutes", 4], ["saxophones", 2] ], 2));

This code is pushing ["flutes", 4] for arr[0] and arr[2].Can anyone explain me, how?

Aditya
@ezioda004
Jun 27 2018 08:52
@shubhamsoni2617 Its not pushing for arr[0] or arr[2]. Its pushing for arr[1] because arr[i].indexOf(elem)==-1 will return true for ["flutes", 4].
Shubham soni
@shubhamsoni2617
Jun 27 2018 09:01
@ezioda004
newArr=[["flutes", 4],["flutes", 4],["flutes", 4]]
Though, it is only true for arr[1].
I think variable 'j' has some role in it but, I don't understand how?
Aditya
@ezioda004
Jun 27 2018 09:05

@shubhamsoni2617 The second loop (j) is iterating through arr[i] twice (arr[i].length == 2) including arr[1] and thats why

if(arr[i].indexOf(elem)==-1){
  newArr.push(arr[i]);
}

Executes twice, which results in newArr = [["flutes", 4], ["flutes", 4]];

Try this code

for(let i=0;i<arr.length;i++){
    for(let j=0;j<arr[i].length;j++){
    console.log(arr[i], j);
    if(arr[i].indexOf(elem)==-1){
          newArr.push(arr[i]);
    }
  }
}
  // change code above this line
  return newArr;
}
filteredArray([ ["trumpets", 2], ["flutes", 4], ["saxophones", 2] ], 2);

Notice the console.log statement and how many times each arr[i] iterates.

Shubham soni
@shubhamsoni2617
Jun 27 2018 09:15
@ezioda004 Alright! Thanks. I think I have got this.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 10:25
Hi
Can anyone help me with this?
Blauelf
@Blauelf
Jun 27 2018 10:33
RegExp is probably the most viable way to go. I used a | to match (555) and 555 but not (555 or 555)
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 10:34
I updated the code minutes ago
Now it's:
(1\s)?(\([0-9]{3}\)|[0-9]{3}(\s|-)?)[0-9]{3}(-|\s)?[0-9]{4}
It solved the problem but now
a code like this doesn't match anymore:
(555) 555-5555
Blauelf
@Blauelf
Jun 27 2018 10:35
Please use backticks or a code block, so one sees the backslashes: (1\s)?(\([0-9]{3}\)|[0-9]{3}(\s|-)?)[0-9]{3}(-|\s)?[0-9]{4}
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 10:35
I think this is the final piece of the code
Okay
Blauelf
@Blauelf
Jun 27 2018 10:36
I think the ) should be before the (\s|-)?, not after.
You want that optional space or hyphen for both, the version with or without the parentheses. So it has to be outside of that group you use for the alternate matching.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 10:37
I tried that but now it matches everything
including:
2 555 555 5555
Blauelf
@Blauelf
Jun 27 2018 10:38
Have you tried ^ and $ ?
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 10:38
Why is that useful though?
Blauelf
@Blauelf
Jun 27 2018 10:38
Because it matches not the 2 555 555 5555, but only the 555 555 5555 part (you never told it the match needs to be the whole string)
^ and $ at the right places fix that part.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 10:46
I placed ^ at the start of capture group and it's ending I put $ and it didn't work.
I even tried ^ after the first capture group and it's endng with $ and it still didn't work
Oh yeah, it worked!
Blauelf
@Blauelf
Jun 27 2018 10:49
Place them around the whole regex. Like /^...$/
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 10:50
It seems that I forgot to change (\s|-)? thing which caused a problem
Are you sure that I have to put $ too? It seems that it works without that and only with ^.
Blauelf
@Blauelf
Jun 27 2018 10:51
At least the ^ is crucial, I don't know whether they have any test case where $ makes a difference. I would add it just to follow the specification which states the whole string is the phone number.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 10:52
Yeessss!
Only 1 test left.
Bjorn van de Peut
@bjorno43
Jun 27 2018 10:52
I think it's also important to know what everything does ;)
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 10:52
Thank you a lot!
Bjorn van de Peut
@bjorno43
Jun 27 2018 10:52
Like you can replace each [0-9] with \d
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 10:53
[0-9] is more understandable to me honestly.
I don't like many \ and symbols, it makes regex look as if it is a mess.
Bjorn van de Peut
@bjorno43
Jun 27 2018 10:53
It's not that hard to understand. \d = digit \s = space \t = tab
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 10:53
I mean when you read it.
The code looks better when you read it when it has less symbols and more human-text.
Bjorn van de Peut
@bjorno43
Jun 27 2018 10:56
Perhaps, but there's an idea behind those symbols. They match unicode defined symbols as where [0-9] does not
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 10:56
Finally! After 8 hours. I passed the challenge/project. Thank you all for who helped me!
Blauelf
@Blauelf
Jun 27 2018 10:57

I struggle most with \w. Alphanumeric plus underscore. Why underscore, but not for example dollar character? Both can be used to begin a JavaScript variable.

And \b ("word boundary", matching nullspace between word and non-word character) is based on that definition.

Yeah, I know that role of underscore. But it does not feel intuitive.

Bjorn van de Peut
@bjorno43
Jun 27 2018 10:58
\w is to match valid variable names for example. Not the initiation of them
Blauelf
@Blauelf
Jun 27 2018 10:59
JavaScript allows me to write variable names like $$$ or CA$H
If we were talking about C, that's obviously the right character set. It does not allow $ in variable names.
Bjorn van de Peut
@bjorno43
Jun 27 2018 11:00
Well you can't expect regex to match language quirks :P I mean, I'm not sure that's even the reasoning behind it. But it makes sense to me
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 11:02
Just a question, is it bad to not pass the fourth challenge of codefights?
I started yesterday and I felt so overwhelmed in the fourth challenge.
Bjorn van de Peut
@bjorno43
Jun 27 2018 11:03
@Blauelf This is what I can find about it that makes some sense: In all flavors, the characters [a-zA-Z0-9_] are word characters. These are also matched by the short-hand character class \w. Flavors showing "ascii" for word boundaries in the flavor comparison recognize only these as word characters.
@OGTechnoBoy I usually only pass 1 or 2 challenges, so nothing to worrie about
Blauelf
@Blauelf
Jun 27 2018 11:04
On gitter, you need to escape _, or put it in any kind of code block. Something I frequently hit with *, too.
Stephen James
@sjames1958gm
Jun 27 2018 11:05
Blame it all on perl
In addition, all Perl variable names must follow these rules: Variable names must contain only letters (a-z, A-Z), underscores (_), and numeric digits (0-9). The first character of a variable name must be a letter (a-z, A-Z) or underscore (_).
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 11:05
My main problem with it is the running time thing.
It is annoying, I mean why it needs to be only 4s?
Stephen James
@sjames1958gm
Jun 27 2018 11:05
@OGTechnoBoy It is challenging you to have efficient code.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 11:05
I'm sure I can make it easily in freecodecamp if not for that condition. Now you can't even make more than 1 loop.
Blauelf
@Blauelf
Jun 27 2018 11:06
@sjames1958gm I guess perl was inspired by what C did. Or both were inspired by a common ancestor. But yeah, it's Perl that brought us perl-style regular expressions.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 11:06
@sjames1958gm Yeah but it is for beginners, shouldn't they start with something easier?
I mean, how you're supposed to slice an array and sum them if you can't make more than 1 loop?
slicing needs irritation, irritation needs loop. Sum needs reduce and reduce is a loop. Unless I missed somethng, is there something else to do?
Blauelf
@Blauelf
Jun 27 2018 11:08
What's the task?
Stephen James
@sjames1958gm
Jun 27 2018 11:09
@OGTechnoBoy Which challenge is this?
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 11:09
adjacentElementsProduct
Stephen James
@sjames1958gm
Jun 27 2018 11:10
@OGTechnoBoy You don't have to slice the array. you can compute the adjacent products as you loop once, keeping track of the largest
Blauelf
@Blauelf
Jun 27 2018 11:11

Umm... creating a bunch of 2-element slices just to throw them away and keep only the product? Interesting idea.

But maybe I reject it so readily only because I learnt programming in languages where one couldn't just "slice" an array, and it would require many more steps, plus you would have to make sure you free that memory later.

OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 11:29
function adjacentElementsProduct(inputArray) { var counter = 0; for(var i = 0; i <= inputArray.length; i++) { if (counter < inputArray[i]*inputArray[i+1]) { counter = inputArray[i]*inputArray[i+1]; continue; } } return counter; } adjacentElementsProduct([3, 6, -2, -5, 7, 3]);
It only works at even arrays. Odd arrays doesn't work.
Blauelf
@Blauelf
Jun 27 2018 11:38
  1. continue; has no effect there, as you are already at the end of the loop body.
  2. You usually wouldn't want <= for looping arrays. inputArray[inputArray.length] is not an array element.
  3. Here you need to ensure even inputArray[i+1] is a valid array element.
  4. I'd use -Infinity instead of 0 as a starting value, just in case your array looks like [-1, 1].
Oddly enough, JavaScript allows you to multiply undefined, so I guess that the wrong loop condition also has no effect. I'd still go for -Infinity or inputArray[0]*inputArray[1] as starting value. (Did I mention I don't like how JavaScript silently fails in so many cases? :rage: )
alpox
@alpox
Jun 27 2018 11:45
@Blauelf I believe that javascript wouldnt even call that a "fail" :smile:
Blauelf
@Blauelf
Jun 27 2018 11:45
It's a kind of soft-fail. And I believe things should fail hard.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 11:49
Is there any reason why browsers' dev tools don't tell you that an infinite loop is about to happen?
It's so freaking annoying.
Blauelf
@Blauelf
Jun 27 2018 11:49
How would they know?
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 11:50
I run some code to test but I got caught in an infinite loop to the point I had to shut down the computer
Freecodecamp(before update) knew about that.
Ogundele Olumide
@Lumexralph
Jun 27 2018 11:51
@OGTechnoBoy because infinite loop is not a bad thing in my opinion. It has it uses too, depending on what you're doing. What if using an infinite loop is deliberate? should it warn me too or throw an error? I'm not sure
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 11:52
It should give me the option to run it or not. Like freecodecamp did before.
Blauelf
@Blauelf
Jun 27 2018 11:53
@OGTechnoBoy The "infinite loop detection" really was just a timer, assuming non-infinite loops will end within a second or so.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 11:54
It's still useful to have though.
Blauelf
@Blauelf
Jun 27 2018 11:54
Or at least I think that's the implementation chosen. repl.it does it that way. It's annoying, as any time I deactivate the check I run into an actual infinite loop :P
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 11:56
I miss when freecodecamp had a good UI, a good code linting(now the syntax is barely colored, how I should know the valid method and what's not because I forgot .?) an infinite loop detection...etc
Now, all of these are lost at the cost of more lessons.
Oh and did I mention how it had a better console? It was telling the results, now it does nothing, nothing at all besides repeating which lessons don't work, sigh.
Aditya
@ezioda004
Jun 27 2018 11:58

@OGTechnoBoy I believe FCC used to use loop protect. If you run an infinite loop you dont have restart the whole computer, you can also close the chrome process from task manager.
One way to kinda prevent infinite loop is

let calls = 0;
function possibleInfiniteLoop() {
  calls += 1;
  if (calls > 100) debugger; 
}

Which will open the debugger and then you can stop the program from there.

OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 12:00
Yeah, something like that as I remember.
Blauelf
@Blauelf
Jun 27 2018 12:03
I also struggle with the new UI. It keeps scrolling down, so I have to scroll up to see the first code line.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 12:04
Yeah and the context menu is awfully long and big.
I barely can copy anything.
What kind of an update is this. Updates were supposed to be helpful and make websites more modern. All what it did is to make the website even less modern. I mean I can make a style for me by using Stylus but it's gonna take forever since I don't know which classes and IDs are supposed to refer to the divisions.
Aditya
@ezioda004
Jun 27 2018 12:08
These are valid points, I guess you can perhaps go to contributors room and raise these issues. I'm sure they'll answer your concerns.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 12:11
Thank you.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 12:17
Oh...then that's why I failed the test. It's not two pairs(2), it's two adjacentelements. That's one misunderstanding caused a lot of problems to the point where I tried to slice it lol.
mpmaan
@mpmaan
Jun 27 2018 13:04
var findEditThenSave = function(personId, done) {
  var foodToAdd = 'hamburger';

  Person.findById({_id:personId},(err, res) => {
    if(err){
      return done(err);
    }
    var oldObject = res.ops[0];
    oldObject.favoriteFoods.push(foodToAdd);
    oldObject.save((err1, res1)=>{
      if(err1){
        return done(err1);
      }
        done(null, res1);
    });
  });

};
can someone explain what am i possibly doing wrong?
i have no clue what t do in this challenge
Simon Cordova
@gbsimon87
Jun 27 2018 13:12
good aft :)
mpmaan
@mpmaan
Jun 27 2018 13:18
i used oldObject = res earlier
but that didn't work as well
Yash Pratap Singh
@convexhull
Jun 27 2018 14:08

Can anyone help me with this ?
I got your point Brad @bradtaniguchi . But then why does this code print 2 ?

'use strict';
let printNumTwo;
for (let i = 0; i < 3; i++) {
  if (i === 2) {
    printNumTwo = function() {
      return i;
    };
  }
}
console.log(printNumTwo());
// returns 2

In this case it appears that the function was executed at the very instant it was assigned to printNumTwo since i is not in the scope when the function is called . I don't seem to understand when exactly is a function expression invoked ?
Is it that the function expression gets invoked twice, when it is assigned and when it is called explicitly ?

Blauelf
@Blauelf
Jun 27 2018 14:11
@convexhull let creates an independent variable each iteration, so the increment goes to a copy of the variable referenced by the function.
Yash Pratap Singh
@convexhull
Jun 27 2018 14:14
@Blauelf but when the function is called explicitly using console.log(printNumTwo()); i is already out of scope. Then what i is referenced by this call to the function ?
Blauelf
@Blauelf
Jun 27 2018 14:15
The function keeps a reference to the i of when it was created.
With var, all those i would be the same variable.
Yash Pratap Singh
@convexhull
Jun 27 2018 14:25
@Blauelf I see. but when var was used ( i in global scope) , then the function referred to the current value of i. So is it that - When i is in scope, the function will refer the current value of i but if it is out of scope (the case of let) , it's gonna refer to the i when it was assigned to printNumTwo ?
Blauelf
@Blauelf
Jun 27 2018 14:26
As I said, with var it's the same, just that there is a single i, not one per iteration.
Blauelf
@Blauelf
Jun 27 2018 14:36

Imagine some code

function makeGreeter(yourName) {
    return function(theirName) {
        console.log("Hello " + theirName + ", I'm " + yourName + ".");
    }
}
var myGreeter = makeGreeter("Blauelf");
myGreeter("Yash"); // logs "Hello Yash, I'm Blauelf."

The function returned by makeGreeter retains a reference to yourName even though the scope is left with the return.

It's the same with the function created in your loop. It keeps a reference to i, which is evaluated on running the function. Only that in one case the variable's value has changed, while in another the change was applied to a copy of the same name but a different scope.

Aditya
@ezioda004
Jun 27 2018 14:38
@convexhull the function is able to remember the value of i because of something called "closure". When the function is executed, it looks for the value of i during its author time. Since let creates an independent variable each iteration as @Blauelf said, the function finds that i and returns that value. In the example with var the function does the same thing but keeps going one scope up until it reaches the global because var are functional scope and there is no function where var is initialized. The lexical scope of function is the current one and not like a snapshot thats why i in case with var is 3.
Yash Pratap Singh
@convexhull
Jun 27 2018 14:45
Thanks @Blauelf @ezioda004 for the help. I finally got it now .
Aditya
@ezioda004
Jun 27 2018 14:52
@convexhull :thumbsup: I'd suggest reading about closures at MDN.
Ankur sharma
@ankur1163
Jun 27 2018 14:57
does anyone able to open 3 windows side by side on laptop?
like udemy course on one window, atom editor second and third browser window
I am trying with 2 windows and udemy video is small
any hacks for this?
tundeiness
@tundeiness
Jun 27 2018 15:12
hello guys...can someone help me format this in ES6? I know something is missing
optFrom.innerHTML+=${<option value='data.id' >data.country</option>}``
Christopher McCormack
@cmccormack
Jun 27 2018 15:13
you may need to escape some of that code for gitter
tundeiness
@tundeiness
Jun 27 2018 15:13
@cmccormack where?
Jason Luboff
@JLuboff
Jun 27 2018 15:13
optFrom.innerHTML+= `<option value='${data.id}' >${data.country}</option>`
@cmccormack You can always quote the post and see the original
tundeiness
@tundeiness
Jun 27 2018 15:14
@JLuboff Thanks!
@JLuboff but this is the proper format right?
Christopher McCormack
@cmccormack
Jun 27 2018 15:15
@JLuboff cool I never bothered to try haha
@tundeiness what issue are you seeing?
Jason Luboff
@JLuboff
Jun 27 2018 15:15
@tundeiness I'm assuming data.id and data.country are your variables?
tundeiness
@tundeiness
Jun 27 2018 15:16
@cmccormack in the code I submitted the data.id was not well formatted and I knew that was where the issue was
@JLuboff yes..they are the variables i'd like to fetch from an API
Nazar
@IsaakNazar
Jun 27 2018 15:17
hey guys, I have a laptop with windows 8, I want to install linux (ubuntu or mint) as a second OS, which one is faster? The laptop is 6 year old, so its veeery slow
Jason Luboff
@JLuboff
Jun 27 2018 15:17
Then ya, you just place the ${} around your variables but the backticks ` around the entire string
tundeiness
@tundeiness
Jun 27 2018 15:18
@JLuboff great!!
Jason Luboff
@JLuboff
Jun 27 2018 15:18
@cmccormack Ya, Pieter taught me that trick a while ago lol
tundeiness
@tundeiness
Jun 27 2018 15:19
@JLuboff one more thing, is there a link I can see to better understand object to object comparison? That issue has been giving me a lot of worries lately.
Jason Luboff
@JLuboff
Jun 27 2018 15:20

@tundeiness Object to Object comparison like

{val : 1} === {val : 2}

? (that above isn't a valid test)

Blauelf
@Blauelf
Jun 27 2018 15:20
To use backticks in inline code, one can use any number of ticks around, like optFrom.innerHTML+= `<option value='${data.id}' >${data.country}</option>` (I used double backticks around, as I have single ones inside)
tundeiness
@tundeiness
Jun 27 2018 15:22
@JLuboff not quite...something like key to key comparison or value to value comparison
@Blauelf noted..
Jason Luboff
@JLuboff
Jun 27 2018 15:23
Ah... I haven't done anything like that in a while lol. I know there is a FCC algorithm challenge that does require something along those lines... @cmccormack or @Blauelf I'll let you step in for this one
tundeiness
@tundeiness
Jun 27 2018 15:24
@Blauelf @cmccormack over to you
Christopher McCormack
@cmccormack
Jun 27 2018 15:25
I don't recall that exercise but if you want to compare objects I'm pretty sure you still have to check the values
and that depends on if you're doing a shallow comparison or deep comparison
Is there something you're specifically referring to @tundeiness ?
Blauelf
@Blauelf
Jun 27 2018 15:27
@tundeiness Comparing objects with === will compare references (so checks whether it's the same object, not equal objects). Problem with comparing objects is that the meaning depends on context. So for some two arrays might be same if they contain same objects, for another the order does not matter, for a third those might not even have to be same objects but those with identical ID. It pretty much depends on what you want to achieve.
tundeiness
@tundeiness
Jun 27 2018 15:29
@cmccormack just either key to key comparison or value to value comparison
Jason Luboff
@JLuboff
Jun 27 2018 15:29
Ah, ya wherefor art thou is the one I was thinking of
I remember i kind of cheated on that one... I stringified the objects to compare :trollface:
tundeiness
@tundeiness
Jun 27 2018 15:30
@cmccormack it's the deep comparison
@Blauelf i never quite got a hang of that exercise though..
@JLuboff I even thought turning them into array would be better but alas!!..I was wrong
Aditya
@ezioda004
Jun 27 2018 15:34
@tundeiness A quick object to object comparison (assuming no other references are there inside the objects).
const obj1 = {name: "John"};
const obj2 = {name: "John"};
obj1 === obj2; //false
JSON.stringify(obj1) === JSON.stringify(obj2); //true
Christopher McCormack
@cmccormack
Jun 27 2018 15:34
Array is just an object with certain properties and methods
Blauelf
@Blauelf
Jun 27 2018 15:40

@ezioda004 Consider

console.log(JSON.stringify({lost:[4,8,15,16,23,42],answer:42}));
console.log(JSON.stringify({answer:42,lost:[4,8,15,16,23,42]}));

Order of properties is order of creation of the properties. So two objects I'd consider equal aren't in the stringified realm.

Jason Luboff
@JLuboff
Jun 27 2018 15:41
@cmccormack So that issue I PM'd you about yesterday...got it all working.. think I was overcomplicating things hah
Christopher McCormack
@cmccormack
Jun 27 2018 15:42
@JLuboff hah yeah seemed pretty complicated
tundeiness
@tundeiness
Jun 27 2018 15:42
@Blauelf there has to be a better way to go about this..
sabahatullah
@sabahatullah
Jun 27 2018 15:42
guys I've a burning question. If a cookie does not contain an expiration date, how long does it last? when I google I find out it would be considered a session cookie. BUT in reality I have never seen it to be working that way. It usually gives it a year expiration. I need your thoughts from your expert minds
Aditya
@ezioda004
Jun 27 2018 15:43
@Blauelf Yeah that comparison assumes a lot of things.
Blauelf
@Blauelf
Jun 27 2018 15:43
@tundeiness As I said, equality depends on what you want.
Jason Luboff
@JLuboff
Jun 27 2018 15:43
Put it this way... the first solution I came up with... required 3 loops just to get the data hjow I wanted...followed by another loop to insert data.. I got the 3 loops(map, filter, forEach) into a single map and then a forEach to insert data via my query. This also allowed me to remove an if/else so my code in one spot reduced to a third of the size.. in the other half the size.. @cmccormack
Christopher McCormack
@cmccormack
Jun 27 2018 15:45
Sounds like it's far more efficient now
tundeiness
@tundeiness
Jun 27 2018 15:46
@Blauelf equality in terms of content ...a deeper kind of equality.
@JLuboff well that's mind bogling for my current state of mind..
Blauelf
@Blauelf
Jun 27 2018 15:47
That's still not well-defined. What is "content"? Names/values of enumerable properties maybe? Or all properties? What about inherited properties? What if the value is an object itself, would you do === comparison, or call the function recursively?
Jason Luboff
@JLuboff
Jun 27 2018 15:48
@cmccormack I'd like to think so. Hah
tundeiness
@tundeiness
Jun 27 2018 15:50
@Blauelf content is based on the question at hand. For example the Wherefore art thou task question.
Blauelf
@Blauelf
Jun 27 2018 15:52

@tundeiness You can make object comparison arbitrarily complex. Also, if you want to support deep comparison (whatever that means), you might run into infinite loops, so you would have to detect those. Which makes things slow.

For Wherefore art thou, we only do a shallow comparison (going only one level deep), and even allow additional properties on one side.

Christopher McCormack
@cmccormack
Jun 27 2018 15:52
@tundeiness for that exercise you don't require the objects to be equal, you need to see if the objects have a property name and then if that property name matches a value
Nate Mallison
@NJM8
Jun 27 2018 15:54
if (memoryAddressOf(objectA) === memoryAddressOf(objectB)) {
  return true
}
lol
Christopher McCormack
@cmccormack
Jun 27 2018 15:57
but isn't that already what a direct object comparison is?
Nate Mallison
@NJM8
Jun 27 2018 15:59
I'm not sure TBH. With an object I would say yes, but I don't think it is because how can that be the case if you define var a = 1, var b = 1 and they are equal? definitely not same memory address
tundeiness
@tundeiness
Jun 27 2018 16:01
@cmccormack true..but honestly it sorta looked like a mind bending exercise.. :)
Christopher McCormack
@cmccormack
Jun 27 2018 16:02
I believe numbers are actually stored in those memory locations that you access with a and b, whereas an object variable stores the memory location for the object
Nate Mallison
@NJM8
Jun 27 2018 16:06
but I don't think it compares the memory address, that's why you have to iterate over the properties and compare them individually. If it could compare the address then a duplicated object would be equal to its parent wouldn't it?
cool
Christopher McCormack
@cmccormack
Jun 27 2018 16:08
it does compare memory addresses
> var obj = {a: 1}
> var a = obj
> var b = obj
> a === b
true
Nate Mallison
@NJM8
Jun 27 2018 16:09
your right
Blauelf
@Blauelf
Jun 27 2018 16:09
@NJM8 What is that code? Is that for a specific JavaScript engine? Why should JavaScript code have access to memory addresses?
Nate Mallison
@NJM8
Jun 27 2018 16:09
Primitives like strings and numbers are compared by their value, while objects like arrays, dates, and plain objects are compared by their reference. That comparison by reference basically checks to see if the objects given refer to the same location in memory.
@Blauelf That's a C wrapper I wrote to get memory address.
ha
Just kidding, I wish
it's just nothing code
@cmccormack I was testing with Object.create(), it must make a copy in a separate space in memory
Blauelf
@Blauelf
Jun 27 2018 16:11
What do you mean? Does the JavaScript engine give away any details of memory layout?
Nate Mallison
@NJM8
Jun 27 2018 16:13
@Blauelf No it was a joke
well
actually it must to be able to compare object
Christopher McCormack
@cmccormack
Jun 27 2018 16:13
@NJM8 yeah I believe it will create a new object, looks like .create only applies the argument's prototype to the new object
Nate Mallison
@NJM8
Jun 27 2018 16:13
yup, I should've been using assign
still not equals
const a = {
  1: 'one',
  2: 'two',
  3: 'three'
}
const b = Object.assign(a)
console.log(a === b)
// false
Blauelf
@Blauelf
Jun 27 2018 16:14
@NJM8 Wouldn't it be Object.assign({}, a) or similar?
Christopher McCormack
@cmccormack
Jun 27 2018 16:15
yes
Blauelf
@Blauelf
Jun 27 2018 16:15
Object.assign(a) would do nothing and return a.
Christopher McCormack
@cmccormack
Jun 27 2018 16:15
but they would still not be equal
Blauelf
@Blauelf
Jun 27 2018 16:15
Equal in sense of === means same object.
Nate Mallison
@NJM8
Jun 27 2018 16:16
Screen Shot 2018-06-27 at 12.15.41 PM.png
Christopher McCormack
@cmccormack
Jun 27 2018 16:16
correct
@NJM8 why is that your expected output?
Blauelf
@Blauelf
Jun 27 2018 16:17
Your code above returns true for me, not false.
Nate Mallison
@NJM8
Jun 27 2018 16:17
@cmccormack just copying the object?
Christopher McCormack
@cmccormack
Jun 27 2018 16:17
returned false for me
Nate Mallison
@NJM8
Jun 27 2018 16:17
@Blauelf really! where are you running it?
Christopher McCormack
@cmccormack
Jun 27 2018 16:17
@NJM8 you put expected output 3 5
alpox
@alpox
Jun 27 2018 16:17
const b = Object.assign(a)
a === b // true;

const b = Object.assign({}, a);
a === b // false;
Nate Mallison
@NJM8
Jun 27 2018 16:18
@cmccormack That comment is left over boilerplate ignore
Blauelf
@Blauelf
Jun 27 2018 16:18
@alpox That's how it looks for me, yes.
Christopher McCormack
@cmccormack
Jun 27 2018 16:19
I got false
> var obj = {a: 1}
> var b = Object.assign(a)
> b === obj
false
Nate Mallison
@NJM8
Jun 27 2018 16:19
oh, I had a bunch of other testing on my test file, got them mixed up
alpox
@alpox
Jun 27 2018 16:19
@cmccormack In your case you would have to use Object.assign(obj)
Not a
Christopher McCormack
@cmccormack
Jun 27 2018 16:19
oh oops good catch haha
tundeiness
@tundeiness
Jun 27 2018 16:19
so gentlemen and ladies what is the final approach in this issue?
Christopher McCormack
@cmccormack
Jun 27 2018 16:20
@tundeiness oh your issue isn't related
Nate Mallison
@NJM8
Jun 27 2018 16:20
so if you include the {} it creates a new object, other wise it's basically just a pointer to the other object?
Christopher McCormack
@cmccormack
Jun 27 2018 16:20
you need to iterate over the Array and check if each object has a matching property then see if the value of that property matches
{} is the new object
Nate Mallison
@NJM8
Jun 27 2018 16:20
yup, interesting, good to know!
Christopher McCormack
@cmccormack
Jun 27 2018 16:21
assign pulls properties from the second argument on into the first
so if the first is the original they should be equal
Blauelf
@Blauelf
Jun 27 2018 16:21
@NJM8 Object.assign will always return its first argument. But it will apply properties from its other arguments to it first.
Nate Mallison
@NJM8
Jun 27 2018 16:22
right, so I'm saying since comparing objects with === checks memory addresses, then var b = Object.assign(a) means b is just a pointer to a
where as var b = Object.assign({} , a) will actually make a new object in memory with the same properites
Christopher McCormack
@cmccormack
Jun 27 2018 16:23
technically they are both a pointer to the same memory location
but that's just semantics
Nate Mallison
@NJM8
Jun 27 2018 16:23
well, it all is in that case, ahaha
Christopher McCormack
@cmccormack
Jun 27 2018 16:24
yeah {} in the assign is the new object with a new memory location
Nate Mallison
@NJM8
Jun 27 2018 16:24
Object.is() supplies the same results
Christopher McCormack
@cmccormack
Jun 27 2018 16:24
transitive property - a = {}, b = a, so b === {}
Nate Mallison
@NJM8
Jun 27 2018 16:25
@cmccormack @JLuboff I got the job! :smile: :fire: :sparkles:
Christopher McCormack
@cmccormack
Jun 27 2018 16:26
@NJM8 the one out of Austin?
Nate Mallison
@NJM8
Jun 27 2018 16:26
yes
Christopher McCormack
@cmccormack
Jun 27 2018 16:26
@NJM8 wow! congrats!
Kudzu
@czhower
Jun 27 2018 16:26
@NJM8 Congrats! Austin is an awesome place.
Blauelf
@Blauelf
Jun 27 2018 16:26
Tim Ferriss recently moved there.
Austin, TX, that is?
Nate Mallison
@NJM8
Jun 27 2018 16:27
Thanks. I'm pretty excited. Going to be a challenge. Creating a SPA for healthcare company, covering CRM, CMS and billing.... in 4 months.
@czhower I'm working remote but maybe it all goes well and they fly me out there sometime for projects. haha
Christopher McCormack
@cmccormack
Jun 27 2018 16:27
Do you have a good sized team?
Nate Mallison
@NJM8
Jun 27 2018 16:27
I'm not sure yet TBH
At least two I know of.
Christopher McCormack
@cmccormack
Jun 27 2018 16:28
oh weird that has normally been part of my interview processes, meeting a good portion of the team
Nate Mallison
@NJM8
Jun 27 2018 16:29
Yeah, I think it's small, the company hired a webdev down there with his own shop, which I think is just him. So maybe just him, myself and a couple people from the healthcare company I would guess
Christopher McCormack
@cmccormack
Jun 27 2018 16:29
Hope they have some CSS experts :p
Nate Mallison
@NJM8
Jun 27 2018 16:29
Haha ouch
me too
Christopher McCormack
@cmccormack
Jun 27 2018 16:30
I just mean so you can focus on the backend stuff :p
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 16:30
What's wrong in this code?
Christopher McCormack
@cmccormack
Jun 27 2018 16:30
But seriously some people are really good at design and CSS, better them than us
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 16:30

``function LongestWord(sen) {

// code goes here
var string;
sen.split(" ").forEach((string,index) => {
if(sen[index].length < sen[index++].length) {
string = sen[index++];
}
});
return string;
}

// keep this function call here
LongestWord("Myno Crynooo Hiiiiiiino"); ``

I want to find the longest word in a string but this doesn't work.
Christopher McCormack
@cmccormack
Jun 27 2018 16:31
@OGTechnoBoy the last iteration will compare against a nonexistent value
Nate Mallison
@NJM8
Jun 27 2018 16:31
yeah I'm not sure what my role is exactly. But I think Vue functionality. So all the SPA stuff. I've looked at the other guys work, it's solid and looks good. Also he uses TailwindCSS which I just started with. It's a joy
tundeiness
@tundeiness
Jun 27 2018 16:31
@cmccormack :(
Nate Mallison
@NJM8
Jun 27 2018 16:32
@OGTechnoBoy backticks go on their own lines, three of them
```
code
```
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 16:32
So...there are no a fix for that except making a new one, right?
Nate Mallison
@NJM8
Jun 27 2018 16:32
you can edit your post
Christopher McCormack
@cmccormack
Jun 27 2018 16:32
@tundeiness you should start somewhere - you need to iterate so make your loop, then you know how to check if an object has a property right?
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 16:33
Oh never mind.
I had an idea right now.
I think I will just use sort() to sort it haha.
Nate Mallison
@NJM8
Jun 27 2018 16:34
you can also use reduce
@OGTechnoBoy You aren't using .forEach correctly
you are treating it like a for loop, let it do the work for you!
Nate Mallison
@NJM8
Jun 27 2018 16:40
function LongestWord(sen) {

  // code goes here
  var string; // initialize to empty string
  sen.split(" ").forEach((string,index) => { // dont need index
    if(sen[index].length < sen[index++].length) { 
      // forEach provides you with each element through the arguments above, you don't access it with index, just string, so to compare string to string you will need a different name either here or above
        string = sen[index++];
      }
    });
  return string;
}
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 16:40
I solved it. I just used sort(). lol I totally forget how useful that method is! But I have to admit that using it for different purposes is quite hard. I mean to sort elements based on length, you have to write b.length - a.length
I will be honest here, I only use forEach because it's shorter and easier to use.
Wait, isn't that loop going to return undefined?
Christopher McCormack
@cmccormack
Jun 27 2018 16:41
I think sort is a perfectly acceptable way to do it :)
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 16:41
At the end of the loop, it will face non-existent element, right?
Nate Mallison
@NJM8
Jun 27 2018 16:42
function LongestWord(sen) {
  let longest = ''; 
  sen.split(" ").forEach(string => { 
    if (longest.length < string.length) { 
        longest = string;
      }
    });
  return longest;
}
loop doesn't need to return anything, just set the outside variable
then just pop in a ternery
function LongestWord(sen) {
  let longest = ''; 
  sen.split(" ").forEach(string => longest.length < string.length ? longest = string : '')
  return longest;
}
tundeiness
@tundeiness
Jun 27 2018 16:44
@cmccormack roooight ;)
Nate Mallison
@NJM8
Jun 27 2018 16:45
but sort is nice to get it to one line
:smile:
function LongestWord(sen) {
  return sen.split(' ').sort((a, b) => a.length < b.length)[0]
}
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 16:49
indeed.
Thank you!
Jason Luboff
@JLuboff
Jun 27 2018 16:51
@NJM8 Awesome man, congrats!
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 16:52
I just knew that Coderbyte is shitty
Whenever I make a correct code, when sending data, the code gets corrupted.
Which results in a wrong code.
Screw it. Codewars for the win!
Blauelf
@Blauelf
Jun 27 2018 17:01
@NJM8 Why a forEach (which I never use)? reduce seems the proper choice.
function LongestWord(sen) {
     return sen.split(' ').reduce((a, b) => a.length < b.length ? b : a, '');
}
Oh, that forEach was part of @OGTechnoBoy 's code.
Jason Luboff
@JLuboff
Jun 27 2018 17:06
@Blauelf I use forEach when I don't need the index and am just manipulating data.
Tiago Correia
@tiagocorreiaalmeida
Jun 27 2018 17:10
You still have access to the index tough
And hey!!
Nate Mallison
@NJM8
Jun 27 2018 17:23
@Blauelf I actually don't usually use forEach, pretty much always reduce or a regular for loop if i want to exit early
Jason Luboff
@JLuboff
Jun 27 2018 17:26
@tiagocorreiaalmeida Yes true
Nate Mallison
@NJM8
Jun 27 2018 17:28
@JLuboff Thanks, exited to get to work. Didn't finish my Backend Cert yet but getting tired of toy apps
Jason Luboff
@JLuboff
Jun 27 2018 18:13
@NJM8 Eh...job expereince is a lot more important I'd say
Nate Mallison
@NJM8
Jun 27 2018 18:43
true, I just like the accomplishment
Jason Luboff
@JLuboff
Jun 27 2018 18:51
Fair enough, won't stop you from getting it
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 19:27
Why this returns "cannot read property toString of undefined" error?
function digital_root(n) { n = n.toString().split("").forEach(value => Number(value)); console.log(n); if (n === 1) { return n; } return digital_root(n); }
Markus Kiili
@Masd925
Jun 27 2018 19:29
@OGTechnoBoy What values are you calling the function with.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 19:29
16
It's job is to sum the digits
like 1 + 6
Markus Kiili
@Masd925
Jun 27 2018 19:31
@OGTechnoBoy The return value for forEach is (always) undefined.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 19:32
Then I will try map()
Why map() makes a lot of NaN between 1 and 6 in an array?
Oh never mind.
I didn't sum them with reduce yet.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 19:39
I replaced forEach() with map() and added reduce, now it makes an infinite loop/recursion(?), what's wrong?
Markus Kiili
@Masd925
Jun 27 2018 19:49
@OGTechnoBoy Are you just summing the digits or something more?
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 19:49
Only the digits.
This is the current code:
Markus Kiili
@Masd925
Jun 27 2018 19:49
@OGTechnoBoy No need for recursion then. Just reduce does it.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 19:49
function digital_root(n) { n = n.toString() n = n.split("").map(value => Number(value)).reduce((a,b) => a + b); if (n.length === 1) { return n; } else { return digital_root(n); } }
No, I need it when something like this happens: 9 + 1 = 10, I need to re-sum the digits of 10 again to be 1 + 0 = 1, until it becomes 1 digit
The code works but too much recursion happens.
Markus Kiili
@Masd925
Jun 27 2018 19:51
@OGTechnoBoy ok, I see.
@OGTechnoBoy n is a number so its length returns undefined there.
You need to turn it into a string before checking length.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 19:53
Oh, I never knew that length only works on strings.
Markus Kiili
@Masd925
Jun 27 2018 19:54
@OGTechnoBoy It only works on array-like objects and functions (if I remember correctly).
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 19:55
Thank you a lot! Now it works perfectly! (little more perfect than the challenge says though lol) thanks to you (:
Markus Kiili
@Masd925
Jun 27 2018 19:55
@OGTechnoBoy :+1:
Blauelf
@Blauelf
Jun 27 2018 19:56
I think I would use a do..while loop and a while loop. Like
function digital_root(n) {
  do {
    var sum = 0;
    while (n > 0) {
      sum += n % 10;
      n -= n % 10;
      n /= 10;
    }
    n = sum;
  } while (n > 9);
  return n;
}
Again, I'm from computer stone age ;)
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 19:56
I'm scared...
Blauelf
@Blauelf
Jun 27 2018 20:02
Why scared? Because I prefer maths over string operations?
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 20:03
Actually, math over string operators is always awesome. because it improves your math skills.
It's just that there are a lot of math operators there
Blauelf
@Blauelf
Jun 27 2018 20:04
n -= n % 10; is necessary only because we are dealing with floating point numbers. In any sane programming language, one could skip that step.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 20:06
I never said it is unecessary lol
Blauelf
@Blauelf
Jun 27 2018 20:06
Oh sh**, that's real maths: return (n - 1) % 9 + 1;
Why did I not think of that one?
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 20:07
Because this is how coding works.
The last day, you're too tired and even a super easy algorithm will be hard for you to solve it.
The next day/break, you're too active that even a super hard algorithm will be much easier for you to solve it.
Blauelf
@Blauelf
Jun 27 2018 20:08
Yeah, but that's the simple test for whether a number is divisible by 9, just add its digits and test whether those are divisible by 9. Same principle.
Joseph
@revisualize
Jun 27 2018 20:49
Phuuuuuuuuuųűůūüûúù#=_"#&"/!/!^!!/!^::^*^&/#!^!!÷#××÷÷=//^^£;#%/@#!/#!#$@!#^:^(€()&/#
Markus Kiili
@Masd925
Jun 27 2018 20:50
@revisualize Hi. That is how we all feel sometimes.
Jason Luboff
@JLuboff
Jun 27 2018 20:51
Yes, yes
Markus Kiili
@Masd925
Jun 27 2018 20:53
@JLuboff Big interview tomorrow. Not much sleep tonight I predict.
Jason Luboff
@JLuboff
Jun 27 2018 20:56
@Masd925 Nice. Whats the position?
Markus Kiili
@Masd925
Jun 27 2018 20:57
@JLuboff It is like part math part coding. Just like my last job. It is only for the rest of the year, but the company is huge.
If I behave, there might be something else there to do.
Jason Luboff
@JLuboff
Jun 27 2018 21:00
Awesome, sounds like theres potential
Joseph
@revisualize
Jun 27 2018 21:13
12yrs of IT experience and after 5mo of searching for a job... apparently, I'm only qualified to be a Help Desk / Support Engineer.
Jason Luboff
@JLuboff
Jun 27 2018 21:15
@revisualize Take what you can get, then look for something else
They say you're more employable when you have a job
Joseph
@revisualize
Jun 27 2018 21:35
Yeah, it is tough.
Jason Luboff
@JLuboff
Jun 27 2018 21:45
You'll get through iot
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 22:09
Btw, can you work at some company just from your home?
Jason Luboff
@JLuboff
Jun 27 2018 22:09
If they allow it...yes
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 22:09
I mean, if the company's location is very far away from your home, can you just work from your home?
Jason Luboff
@JLuboff
Jun 27 2018 22:09
If they allow it...yes
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 22:09
Can interviews be done that way too?
Jason Luboff
@JLuboff
Jun 27 2018 22:09
If they allow it...yes
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 22:10
Just a question, when you feel yourself that you're ready to start the work at freelancer?
I have seen some projects there and I'm quite scared, they are complicated.
Jason Luboff
@JLuboff
Jun 27 2018 22:12
I'd say a freelancer would need a portfolio of work to demonstrate their skill set
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 22:14
What is the least min-amount of projects you put in your portfolio to make yourself look professional and confident?
Jason Luboff
@JLuboff
Jun 27 2018 22:20
I'm not positive. I've never worked as a freelancer
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 22:21
I mean a general portfolio.
Jason Luboff
@JLuboff
Jun 27 2018 22:21
I guess I should rephrase, I've never made a professional portfolio. So not positive.
OGTechnoBoy
@OGTechnoBoy
Jun 27 2018 22:21
Okay.
Good Night!
lol it's already 11:22PM.
Jason Luboff
@JLuboff
Jun 27 2018 22:44
Hmm.. well this is annoying.. Edge and IE aren't playing nice.. send some data via ajax to my backend... first time, it goes in undefined, second time the data is there. Chrome and FF work fine.. (this is using body parser)
Kira
@codeymason
Jun 27 2018 23:10
Hi everyone. I've been searching for an answer to the following question and am coming up dry: When checking for a property within nested objects, would one use obj.hasOwnProperty(prop) referring to the outermost object and searching for the specified property anywhere within it, or would it be something more like outerobj.innerobj.innermostobj.hasOwnProperty(prop) ?
Also, if anyone is willing to look at my code for the Basic Javascript: Record Collection assignment, let me know. I could really use a second pair of (more advanced) eyes.
Brandon Vi
@bvi1994
Jun 27 2018 23:21
Hey everyone. I'm having some issues with Cash Register
essentally, I'm dealing with the rounding issue with a test casrt
This is what I have in my console
checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]) current change: 0.009999999999994869
Jason Luboff
@JLuboff
Jun 27 2018 23:22
@codeymason .hasOwnProperty() is single level, that is,
const obj = {'key1' : {'key2' : 'val'}};
console.log(obj.hasOwnProperty('key1')); //true
console.log(obj.hasOwnProperty('key2')); //false
console.log(obj.key1.hasOwnProperty('key2')); //true
Brandon Vi
@bvi1994
Jun 27 2018 23:25
function checkCashRegister(price, cash, cid) {
  const currencyValues = {
    'PENNY': .01,
    'NICKEL': .05,
    'DIME': .10,
    'QUARTER': .25,
    'ONE': 1.00,
    'FIVE': 5.00,
    'TEN': 10.00,
    'TWENTY': 20.00,
    'ONE HUNDRED': 100.00,
  }
  let status = {};
  let returnChange = {};
  let cidObject = convertToObject(cid);
  let change = cash - price;
  for(let bills in cidObject){
    while((change >= currencyValues[bills]) && (cidObject[bills] > 0)){
      change -= currencyValues[bills];
      cidObject[bills] -= currencyValues[bills];
      if(!returnChange[bills]){
        returnChange[bills] = 0;
      }
      returnChange[bills] += currencyValues[bills];
    }
  }
  console.log('current change: ', change)
  if(change){
    return {'status': 'INSUFFICIENT_FUNDS', 'change': []};
  }
  console.log('Status: ', {'status': 'OPEN', 'change': toArray(returnChange)});
  return {'status': 'OPEN', 'change': toArray(returnChange)};
}

function convertToObject(array){
  let Object = {};
  for(let i = array.length - 1; i > -1; i--){
    Object[array[i][0]] = array[i][1];
  }
  return Object;
}

function toArray(object){
  let newArray = [];
  for(let key in object){
    newArray.push([key, parseFloat(object[key])]);
  }
  return newArray;
}

checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])
that's what I have
(And yes, I'm fully aware about the closed case but I'm not implementing that just yet)
Kira
@codeymason
Jun 27 2018 23:34
@JLuboff Thanks!!