In previous video, visual to function cello comparison.
But you can also get the question, OK, but how we can write a function for deep comparison.
This is what we want to do in this video.
And actually, as you can see, I didn't remove any code I have here, typeof and cello compare.
And they want to copy, paste it fully and compare later with dip comparison.
This is why, as you can see, I copied pasted the whole function and they just want to rename it to
deep compare.
And actually, the code will be 90 percent similar because first of all, we want to check for data
type and it has stayed the same and that the and we will compare date and source and target for primitives
in the same way.
So actually, we must just change comparison of our arrays and objects and actually even the code inside
will be almost the same.
So first of all, for race where check in length.
And here we have every.
But here we must remove our comparison of element because it is native comparison.
But here we want recursively to check every single element.
This is why here we can simplify deep compare.
And we're throwing inside our element comma Typekit index in this case, what we're doing.
Well, Colin did compare again and actually here it might be that we have an object then were common
recursively and so deep compare and we will compare the subject and we're doing it again and again until
we compare the whole object or the whole array.
And it doesn't matter how deep this object is or how deep this race, which actually means this is not
performant.
This is really slow, but it will give you that on the correct answer.
When you are working with nested data and exactly the same, we must do now with our objects.
So here we can leave our comparison whiskey's.
This is totally fine.
Here we have our every.
But we must remove this comparison and call deep compare instead.
And we are passing inside our source key and here touch it key.
In this case, we are comparing two values of our target and our source.
And we also do it with dip comparison.
And this is actually it were fully transformed our shallow comparison function in deep comparison.
Let's check this out now.
I will reload the page here first or compare a 181.
It is true, but actually here inside shallow compare if I will throw a big one.
So we have a nested object in here, a b one, it will return false, which actually means shallow compared
can't work with nested data.
But here we are calling our deep compare and we're getting through because deep compare is the recursive
and it will compare any nested correctly in exactly the same we have for race.
For example, if we have a real phrase, let's say a ray with a one.
And here we have array and array one inside, as you can see where and true, and we can compare arrays
of any level.