Hi! As the tutorial went on, I have noticed that "//?" in vscode led to an "shortcut" output. Can you let me know which extension this is? Also, is this available on replit?
Another amazing video... Great explanation and exemplification... You totally deserve more subscribers... Just a quick question, what is the plugin which are you using to execute conde inline with "//?"...
but if the objects are inside on the array. var hunterco = [{ candidato: "Anderson", evento: "REPROVADO", }, { candidato: "Anderson", evento: "REPROVADO" } ]
@edutechinal May I ask how you get direct return values in the code editor? Thinking.. line 17: isEqual(obj1, obj2) .. your blue text changes as you write code.
Surely this'll fail if obj1 & obj2 have the same number of keys but one of obj1's keys return `undefined` (&, perhaps, if one of obj2's (differently-named) keys return `undefined`). For example, obj1 has `color: undefined` & obj2 has `shape: undefined`. `obj1.color`'ll return `undefined` but so will `obj2.shape`. `obj2.shape`'ll return `undefined` but so will `obj1.color`. It's an edge-case but could still catch people out.
To me it depends on the situation. Stringify is easier to remember, so it might be the best option in a coding interview, but if you're building an application in a tool such as React, or Vue, it's recommended to use tools such as pure components.
The problem though is this only works if the keys are in the same position for both objects which might not be the case for alot of problems for example if you create an object to store value counts.
Is it possible to compare two different objects, then set all the values in the longer one, equal to the shorter one (while keeping the other ones as they are)? So for example: var obj1 = { name: "Bob", age: 18, pet: "cat" } var obj2 = { name: "Kristine" age: 13 } and then make obj1 = { name: "Kristine", age: 13, pet: "cat" }
Yes, for something like that you can compare the object keys and then add the key(s) that are different: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
I create a function airplane (model, seatingCapacity,maxSpeed){ this.model=model; this.seatingCapacity=seatingCapacity; this.maxSpeed=maxSpeed; } Var obj = new airplane ("A 7745", 150,450); I want increase value seatingCapacity by object 10 And delete maxSpeed for all object And add new property average speed for all object with value 600
Hi! As the tutorial went on, I have noticed that "//?" in vscode led to an "shortcut" output. Can you let me know which extension this is? Also, is this available on replit?
Another amazing video... Great explanation and exemplification... You totally deserve more subscribers... Just a quick question, what is the plugin which are you using to execute conde inline with "//?"...
I'm glad that you found it helpful! And it's the Quokka JS extension, I show how to use it in this video: ruclips.net/video/1ABsTHKchLY/видео.html
Sweet can of corn! Finally someone who answered my question!
I'm glad it worked for you!
but if the objects are inside on the array.
var hunterco = [{
candidato: "Anderson",
evento: "REPROVADO",
}, {
candidato: "Anderson",
evento: "REPROVADO"
}
]
Thanks Jordan, always so kind.
@edutechinal
May I ask how you get direct return values in the code editor?
Thinking.. line 17: isEqual(obj1, obj2) .. your blue text changes as you write code.
I use the Quokka JS extension
Awesome, thank you very much!
I've purchased two Ruby courses from you as well and am very happy!
I'm glad that you are enjoying them, thanks!
is the lodash function using the recursion internally? Cannot think of a different implementation
Great explanation and on the point. Thank you.
Surely this'll fail if obj1 & obj2 have the same number of keys but one of obj1's keys return `undefined` (&, perhaps, if one of obj2's (differently-named) keys return `undefined`). For example, obj1 has `color: undefined` & obj2 has `shape: undefined`. `obj1.color`'ll return `undefined` but so will `obj2.shape`. `obj2.shape`'ll return `undefined` but so will `obj1.color`. It's an edge-case but could still catch people out.
Isn't better to just JSON.stringify() both objects and compare the strings?
Absolutely, you can do that as well. One of the purposes of this guide was to show a tricky part of JS that a number of my students have run into.
Cool! But which one you recommend? In my humble opinion, the JSON.stringify is much faster :)
To me it depends on the situation. Stringify is easier to remember, so it might be the best option in a coding interview, but if you're building an application in a tool such as React, or Vue, it's recommended to use tools such as pure components.
Thanks! :)
The problem though is this only works if the keys are in the same position for both objects which might not be the case for alot of problems for example if you create an object to store value counts.
2021 and this is super useful
this video is highly educational...Thank you
In my case I have nested object. I have to check equals without using library. Please help me out on this one
You can convert the full object (or nested element) into a string using JSON.stringify and then then compare it that way.
are you using a free version of Quokka JS? That functionality really helps see your output
I'm using the paid version, but the free version has quite a bit of functionality as well!
Thanks for the great video. I figured out how to do deep comparison of objects using recursion.
const isEqual = function(obj1, obj2) {
const obj1Keys = Object.keys(obj1);
const obj2Keys = Object.keys(obj2);
if(obj1Keys.length !== obj2Keys.length) {
return false;
}
for (let objKey of obj1Keys) {
if (obj1[objKey] !== obj2[objKey]) {
if(typeof obj1[objKey] == "object" && typeof obj2[objKey] == "object") {
if(!this.isEqual(obj1[objKey], obj2[objKey])) {
return false;
}
}
else {
return false;
}
}
}
return true;
};
Hope this helps!
Thanks for sharing!
can you explain how line work >> !this.isEqual(obj1[objKey], obj2[objKey])) how this "this" come , and how works
What IDE are you using? Looks super clean
It's Visual Studio Code.
which extension are you using for getting the result in vsCode?
Quokka JS
thank you man i love this video
You're welcome!
how to compare two json have the same properties without order? let obj1 = { name: "person 1",age:5}; let obj2 = {age:5, name: "person 1"};
Great explanation!
I greatly appreciate it!
what if is use
function isEqueal(a: object, b: object) {
return JSON.stringify(a) === JSON.stringify(b);
}
Awesome, thank you very much!
Crystal Clear.
Is it possible to compare two different objects, then set all the values in the longer one, equal to the shorter one (while keeping the other ones as they are)?
So for example:
var obj1 = {
name: "Bob",
age: 18,
pet: "cat"
}
var obj2 = {
name: "Kristine"
age: 13
}
and then make
obj1 = {
name: "Kristine",
age: 13,
pet: "cat"
}
imgur.com/a/ON0gti2
I think I figured it out lol
Yes, for something like that you can compare the object keys and then add the key(s) that are different: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
What is he using to debug?
The Quokka JS extension
I create a function airplane (model, seatingCapacity,maxSpeed){
this.model=model;
this.seatingCapacity=seatingCapacity;
this.maxSpeed=maxSpeed;
}
Var obj = new airplane ("A 7745", 150,450);
I want increase value seatingCapacity by object 10
And delete maxSpeed for all object
And add new property average speed for all object with value 600
Great!
if(JSON.stringify(obj1) == JSON.stringify(obj1)){
return true
}return false
OVER !
this fails when order of key is different