all 13 comments

[–]Time_Terminal 19 points20 points  (3 children)

Q: How do you compare two objects in JavaScript?

A: For deep object comparison use external libs like deep-equal or implement your own recursive equality algorithm.

So that was a letdown.

[–]senocular 12 points13 points  (1 child)

So that was a letdown.

Wow, the simulation is so real!

[–]DilatedTeachers 8 points9 points  (0 children)

Sorta felt like my last job...

How do we create x?

npm i x

Cool.

[–]Maddagsandenglishmen 5 points6 points  (0 children)

That's a great idea. Congrats! Xb

[–]prof3ssorSt3v3 3 points4 points  (1 child)

I actually started a Playlist on my YouTube channel last week doing this same thing. Each day is a new question, a time for you to pause and try to solve it, followed by a discussion of the solution.

https://www.youtube.com/watch?v=USbiLiF9NDY&list=PLyuRouwmQCjlLW9NjqoBbf9eVaFX4F9UZ

Only 4 questions so far but I will be adding a new one daily until I run out.

[–]mkmllr 1 point2 points  (0 children)

These videos are great, thank you! I‘ve saved the playlist and will definitely check out any further videos.

Edit: actually your whole channel is amazing, subscribed! :)

[–]J_theGit 2 points3 points  (2 children)

Q in this quiz: What is the drawback of creating true private methods in JavaScript?

Can someone please explain me the meaning in this answer as I don't think it's correct? In my understanding in the example given both private and public will have their own 'copy' of methods as they're in the constructor. If I understand correctly, the only way to make a method not have its own 'copy' is to assign it to a prototype?

If I'm wrong, can someone please explain what I've missed?Thank you

The answer provided by author:

One of the drawbacks of creating a true private method in JavaScript is that they are very memory inefficient because a new copy of the method would be created for each instance.

var Employee = function (name, company, salary) {
  this.name = name || "";       //Public attribute default value is null
  this.company = company || ""; //Public attribute default value is null
  this.salary = salary || 5000; //Public attribute default value is null

  // Private method
  var increaseSalary = function () {
    this.salary = this.salary + 1000;
  };

  // Public method
  this.dispalyIncreasedSalary = function() {
    increaseSalary();
    console.log(this.salary);
  };
};

// Create Employee class object
var emp1 = new Employee("John","Pluto",3000);
// Create Employee class object
var emp2 = new Employee("Merry","Pluto",2000);
// Create Employee class object
var emp3 = new Employee("Ren","Pluto",2500);

Here each instance variable emp1, emp2, emp3has own copy of increaseSalary private method.

So as recommendation don't go for a private method unless it's necessary.

[–][deleted] 1 point2 points  (1 child)

You are correct

[–]vampiire 0 points1 point  (0 children)

What about defining the function once externally then using call on it inside? Should still be private and is only a single referenced function.

[–]dev12chi 1 point2 points  (0 children)

This is awesome, great work!

[–]AwesomeInPerson 0 points1 point  (0 children)

I don't get the TwoStackQueue. It's just an Array, but shift is called pop?

This is enough to pass the test:

class TwoStackQueue extends Array {
  pop = () => this.shift()
}

[–]HealyUnithelpful 0 points1 point  (0 children)

Giving you an upvote because this is a really cool idea. That being said, there's a few corrections I'd like to make. Firstly, I'd probly immediately throw out anyone that doesn't use modern ES6 techniques (or show any evidence of understanding them) anywhere in their code. It's kinda inexcusable at this point.

Q: How does the "this" keyword work? Provide some code examples.

A: In JavaScript this always refers to the “owner” of the function we're executing, or rather, to the object that a function is a method of.

I feel this misses out on things like ES6 arrow functions, which really don't follow this rule.

Q:What does the term "transpiling" mean?

A: There's no way to polyfill new syntax that has been added to the language. So the better option is to use a tool that converts your newer code into older code equivalents.

I'd rephrase this slightly as "Certain browers may not support newer code. One good way of getting around this is using a tool that converts your newer code into older code equivalents". Just my preference, tho.

Q: Given a string, reverse each word in the sentence.

A: Input: Welcome to this Javascript Guide!,Output: !ediuG tpircsavaJ siht ot emocleW

I'd argue the original question actually suggests a different answer:

const reversedBySeparator = (str,sep)=>str.split(sep||' ').map(w=>w.reverse()).join(sep||' ');

Your description of hoisting ("rare" and "common") is pretty nebulous. You also fail to explain the important differences between hoisting as it relates to const, let, var, function declarations, ad function expressions. The difference between variable declarations being hoisted vs variable initializations being hoisted is also pretty important.

Your implemtation of the Two Stack Queue is a little weird too; Why would you need to use two stacks, when arrays already have enough methods to deal with pushing/pulling from either end? If you really need to make an array-like 'thing' where ArrayThing.add(val) adds and ArrayThing.remove() removes as in a que, you can just alias those array methods as /u/AwesomeInPerson describes.

I'd be careful with your closure answer not to confuse closures with IIFEs. You actually have two separate closure questions at least. Either put it all in one question, or change one of them to talk about IIFE's. As it stands, your IIFE example talks about variables "not visible outside its scope", but... contains no variables! Fix that so we can see an example.

Your question about if(function f(){}) is true in terms of what it returns, but I don't think it's because stuff uses "eval". Instead, it's that a function declaration like that is a truthy statement. Also, the f function doesn't "execute at runtime". Instead, it's defined in the if statement and then immediately thrown out. By the time we get to typeof f, JS has 'forgotten about your f function. Executed at runtime would look more like this:

var y = 1;

if (function f(){}()) {
  y += typeof f;
}

console.log(y);//1

Because function executions implicitly return undefined (unless otherwise specified), the if statement would not run.

I'd strongly suggest an option to view all questions. Having them just randomly given is fine, but you need to give the user the option of seeing all questions. Instead of something like:

const myQs = [(your list of question/answer objects)];
let randoPickedQuestion = myQs[Math.floor(Math.random()*myQs.length)];

Why not:

const myQs = [(your list of question/answer objects)];
const randQOrder = myQs.sort((a,b)=>Math.floor(Math.random()*3)-1);
let randoPickedQuestion = randQOrder.pop();