Here's one more task for you, which is taken from the rail project.
So this is not just some task for the interview, but the task that you will see in your everyday life.
And as you can see from must map data to the front and format, which actually means we're getting our
data, for example, from the back, not informant like we want.
This is why we want to convert them.
And the main element is location key, and we need to map all data to it and we will have it then five
objects, as you can see here.
First of all, we have a location array and here we have two objects.
First of all, location key.
And this is our unique identifier and we have here some ideas and outside and exactly the same in the
second object.
And now here we have a bulk configuration.
So this is also the array with objects and inside every single object.
We have a data values and confer key.
The main point is that we're making them one to one, which actually means the ZOHRA Index in location
array equals bulk config zero index.
And in this case, we need to map everything to this structure.
So at the end, we must get an array of objects with, first of all, config key.
This is the spot and location key 32mm.
As you can see, your location key 32 is that this part and also outer assigned from it, which actually
means our a second element will also conflict.
100 location key 22.
This is our second number and then aside and so on and so on.
And this is said the unique difference is this, which actually means we're getting here one two three
four five objects.
So at the end, we must have an array with five objects.
Now, let's try to ride this logic, and actually we won't hear anything complicated here.
It's all about data mapping.
So let's right here our result as they want to do it directly result for loops inefficient way.
And they want here to work with location just because inside we have our unique ideas and here in said
location, we're getting map, which actually means we're looking through these objects.
And here inside the map, we're getting location element and also where get in here?
Index.
This is why I must put additional brackets here.
Solar case and index are what we need to.
And now inside, we can do our magic because now inside location element, we're getting every single
object.
So we want here one more map because inside our location element, we want to move through our location
key.
This is where here we can return our location element.
And here we have our location key.
And here I also have a map and we have access to our location key.
And as you can see, I wrote it with camel case because we are right in JavaScript code and typically
all our variables are camel case.
Here inside, we want to return what we need to.
And first of all, we need here allocation key.
This is why here I am, right in location key.
We can live it with underscore like from beckoned over.
Can convert it to uppercase.
Just depends on what you want.
And here we are, just assigning our location key.
After this, we must get our config key.
And this is extremely easy to do because here inside bulk config, we can just get this config key by
index.
This is where here we can write bulk config index because it is the same lake and location dot data
values dot config key.
And the last part is ultrasound and ultrasound, where getting inside location, element dot ultrasound.
And this is how we mapped what we needed.
So first of all, we have a map through our location, through this subject and in America for our location.
This is why, for every single unique ID, we can map data that we need to.
Let's check this out.
I will write console.log here.
Our result?
Endless.
Check if it's working.
I'm reloading the page and we get an array of race.
And in the first three, we're get an allocation key conflict, older, assign and all is good.
The only problem that we have is that we get an array of race, but we actually want a flat array.
This is why we must do something with this code and we can use here reduce to just create a flattery
because we don't have fled the method natively inside JavaScript.
So here we have our array and accumulator.
And at the beginning, we can say that we get an empty array.
And what we want to do inside is to use array dot concatenate.
And here were concatenate in.
This was accumulator.
So what is done here by default?
We have here empty array and we have every single array that you can see here.
And we want to concatenate our array with accumulator.
So essentially, for every single element Vulkan could donate and it was our accumulator.
Let's check the time to load in the page and we're getting our flat array of subjects.
And this is how you map data, for example, from in format to our frontend format.