Jonas: Okay, let's keep working on our
recipe model now,
this time writing a complex function,
to process the ingredients list.
And so we will use a lot of stuff here,
like using array methods like map, slice, find index,
and includes, and you will also learn how and why
to use the eval function in JavaScript.
So in this lecture, what we're trying to do,
is to basically read through a list of ingredients,
and in each ingredient, separate the quantity,
the unit, and the description of each ingredient.
So for example here, we have four ounces of cream cheese.
And here we have have 1/4 of a cup of sour cream,
and we need to have add them separately for two reasons,
first because we later want to implement this function,
where we can decrease and increase the number here,
so of course, we need to have them in separate variable.
And the same thing happens,
when we add this to the shopping list,
we also have them separated here in the number,
and the unit, and then the ingredient itself.
So we can for example, update this number here,
and everything of course, stays the same.
Okay, so we need a way to read through
a list of ingredients and then parse
each ingredient into the count,
the unit, and the description of the ingredient.
So let's take a look at a couple of our results here.
So let's say pizza again.
So let's what for a data hit to come back
for this first recipe.
And here we go,
and we have our ingredients here,
and you see that we have these number here,
like, 4 1/2 cups,
then we have some stuff here in parentheses,
then we have teaspoon, we have cup,
now we have cups, okay.
And so all of these units, they are all different,
in each of the recipes.
So here we have like teaspoon,
but if we go, into this last one here,
let's wait for it,
if we take a look here now,
for example here we have tbsp, which stands for tablespoons,
but then we have teaspoons again, spelled out like this.
And so here we have cups,
and probably somewhere else we have cup.
And so we to first, before we actually start,
parsing the ingredients,
we first need these units to be all the same
across all of the recipes.
So that we don't have sometimes, teaspoon,
and at other times, teaspoons,
and then tbsp, and so on and so forth.
So when we have cup, or teaspoon, or ounce,
we always want it to be the same, okay.
And we also want to get rid here,
of these parentheses okay, because,
they don't really add anything here,
in most of the cases, okay.
So we're getting rid of the parentheses,
and then we need to kind of standardize the units.
So let's start by doing that.
So the recipe, and we add a new method,
parse ingredient,
and so what we're going to do is, to create a new array,
with some new ingredients based on the old ones.
Okay, so const,
the new ingredient,
is this dot ingredient, and now we will use the map method.
So basically a loop of ingredient,
where in each iteration, we can save new item,
to this new array here.
So in each of the iterations,
we have to simply return a value,
which will then be stored into the new ingredients array.
Okay, remember that from one of the previous projects?
So we pass in the element,
and then we have our callback function in here, basically.
And then finally we will then say that,
this dot ingredient, will be the new, ingredient.
Okay, so that's basically how this is going to work.
And so let's define what we are going to do.
So first we want uniform units,
so all the units should be all the same,
then we move parentheses,
and finally,
into count unit, and the ingredient itself.
Okay, so how are we going to do this first task?
Well, what I'm going to do is to create two arrays,
in one array we will have the units
as they appear in our ingredients,
and in the second array, we will have them written,
exactly like we want them to be, okay.
So let's do that out here,
so units long,
and so let's say that we have tablespoons.
But we want it to be,
tbsp.
And what we're going to do here, is then to loop,
through this array here,
and see if one of these long units is there,
and if it is, then replace it by the short version.
Okay, now sometimes we saw, that we also have tablespoon.
Like this, okay, and that is, of course,
still tbsp, and so that's one of these cases,
where tablespoons or tablespoon can appear,
but we still want it always to be the same.
Okay, and so that's a great use case,
for why we have to uniform these units like this.
And the same happens with ounce.
So it may appear ounce, or it may appear ounces.
And of course, they should both be oz, okay.
And so we have these data structures here,
which store the way that it may appear in the recipe,
and then the way that we actually want it to look.
Now another example is teaspoon,
and teaspoons, so again, a plural,
but we really want the abbreviation of tsp like this.
And then finally, we may also encounter cups, or pounds.
And cups, we want it to cup,
and pounds, we want it to be, just pounds.
Alright.
Now let's create a variable here called ingredient,
which will be based on the current element,
right, so right now this element here is
each of the elements of the array.
And so we said ingredient to that l,
but to lower strength.
Or to lowercase.
Okay, and that's because,
it may even sometimes appear like, with a capital T,
something like this for example.
But we don't want to include all of these cases here
in our long units, instead,
we can simply convert everything to a lowercase,
and then can start from there.
Okay, and I'm using a let here,
because we are going to mutate this variable
here in a second, and so therefore,
we cannot use const, because then we could not change it.
So, as I was saying we are now going to loop
over the long unit, so that ones that are appearing
in the ingredient.
So we use for each, and this is how it's going to work.
So let me first write it out,
and then I'm going to explain it to you.
So in our callback function,
we need both the current element,
which I call unit here, and then also the current index.
Okay, and what we're then going to do is,
to manipulate the ingredient variable,
as I mentioned before,
so the one that we created up here.
And we will,
replace.
And what we're going to replace,
is the current unit, so that's the unit here,
in this callback function,
with the unit short that we want.
So unit short, at position i.
Okay, does that make sense?
So the tablespoons here, for example,
is at position zero, and this tbsp here, is also at zero.
And so if we find this tablespoons in the ingredient,
then it will be replaced with the unit
at the same position, but in this other array.
So unit short, as we have here, okay.
So again,
we loop over each of these long unit possibilities,
and replace that text with the shorter version,
which appears in the same position.
That's why we have to repeat these here, for example,
tablespoons, tablespoons,
they're both the same here,
but we have to repeat them,
so that they are still on the same position.
Right, so for example, this one here,
is at position number five, six, seven,
so cup is at position seven in here,
and in here as well.
So that they can still match
when we do this replacement here.
Okay, and so right now, the current ingredient,
no longer has the long unit, but the short unit,
and so we can now move on to the second step,
with our ingredient already with the short unit in there.
Okay, so next up, let's remove the parentheses,
and that should be a bit easier.
And now sometimes when you're developing,
you might now know how to accomplish a certain task,
and so what you do is, to basically Google it.
So let's do that together now,
just so I can show you how I usually do it.
Okay.
So, what I would do in this case is just simply write,
JavaScript,
remove parentheses.
Okay, so let's take a look at the results here,
remove parentheses from string,
remove text between parentheses.
So this is here actually what,
we're trying to accomplish.
Then we can take a look at the example,
and see if it applies to our case,
and so yeah, so imagine we have this,
and we want this, so,
the parentheses including the text, should be gone.
And so the solution is to use something like this.
So we can just go ahead and copy it,
and I'll will explain it to you in a second,
how this works.
But for now, let's simply grab it, and use it here.
Okay, so we want ingredient to be ingredient,
and then replace.
I've yet to store it here in the new variable,
because this doesn't change the underlying variable,
but instead, it returns a new one.
And so we have to change that result somewhere, okay.
Now what is this weird replace here?
That's what it is called a regular expression,
and let me show that to you also here,
so let's write mdn,
regular expression.
And regular expressions are kind of complex topic,
in programming, because they're really quite confusing.
But in essence, regular expressions are like
patterns used to match character combinations in strings.
Okay, so that's exactly what we're trying to do
in our example,
we're trying to match a character combination,
which starts with the opening parentheses,
then has some text in it,
and then closes the parentheses at the end.
So not going to teach you all about regular expressions,
but as the basics, what you need to know,
is they always start with the slashes,
so they start and end, and so that's what we have here.
So we start and we end here with the slash,
and so we already know that this is a regular expression.
Okay.
So let's replace this here by, for normal quotes,
which are the ones that we've been using all time.
And so we want to replace everything that is
inside the parentheses and the parentheses themselves,
with nothing.
So let's take a look again at the regular expressions,
and all the symbols that are in the regular expressions,
they have different meanings.
So for example, if you write this hat here,
then it matches the beginning of an input.
Or this dollar sign here matches the end of an input,
this symbol here means that the proceeding expression
can happen zero or more times.
And, so on and so forth.
So this is really a lot of stuff that you can do here
with regular expressions.
Again, in order to match different situations, in a string.
Okay.
So let's take a look again at ours,
so an arbitrary amount of spaces,
after that parentheses symbol, after that,
an arbitrary number of other characters,
then the closing parentheses,
and then again, and arbitrary number of spaces.
So whenever we match that, we are going to replace it
with a space, okay.
And whenever you need something like this,
you can usually just Google for regular expressions,
for achieving something like this.
So you can find regular expressions
for matching certain types of phone numbers,
or of an email address,
or of a zip code, or whatever you need really,
to match in a string,
there's always a regular expression for that.
And if you want to try to come up with your own,
well then, you can just try to read this tutorial,
or read some other tutorial online,
and there are tons of them.
So this one here removes for parentheses, okay,
and so let's now actually try to test it out,
to see how it works, at this moment.
Now before we can do that,
we actually have to return something from here.
So return the ingredient.
Okay, so as I explained at the beginning,
that's how the map method here works.
So in each iteration, we have to return something,
which will then be saved into the current position,
of the new array.
Okay, now in order to not always have to,
write in pizza, or whatever else you might be searching for,
when we're testing, let's actually,
do the same here for the load, event.
Okay so basically this is just for testing,
that's right at here,
so whenever we test, we will start the control search,
and we will, instead of getting from input,
we will simply write pizza.
So let's check that out.
And it doesn't work,
and,
yeah, of course.
I need to add this one here to the window.
Alright, so let's wait for it.
And yeah, so automatically pizza returns,
instead of us having to write it here, out,
all the time.
Now something else that we can do here,
for testing purposes again,
is to, let's take a look at it,
is to expose this recipe here, to our global window.
Because right now, in the console,
we don't have access, neither to the state,
nor the recipe or the search, or any of that really,
because it's not exposed to the global object.
Okay, but we can't do that, so we can do,
let's say, window dot r, which is going to stand for recipe,
equals state, dot recipe.
So testing again, and so right now,
we will have access to the recipe object,
right in the console,
because it's on our global window object.
Okay, so let's test it out again.
And as soon as I select something, when it comes back,
now it's type r,
and indeed here it is, so here's our recipe, okay.
And so now we can then go ahead and call,
that parse ingredients method on it.
So for example, this one here, we have,
ounces, cup, cup, and ounces and tablespoons,
all written out as a long form.
So let's now say r dot parse ingredient,
let's take a look at r again,
so it should by now have changed our ingredients, right.
And so it did actually replace,
so now it says, ozs, to ounces,
well something is not right here,
but it's probably just an s that I put too much.
But here it converted the tablespoon as long unit,
as it was here, to tbsp, right.
So that's perfect.
And I see why it did that ozs thing,
even if it's not written out here like this,
it's because it found ounces probably,
but then only replaced ounce, and so the s stayed there,
and it was then ozs.
And so we have turn it the other way around.
So the s first,
and then the singular.
And the same here for teaspoons,
and then only teaspoon.
Okay, so that's a small detail, it's not a big deal,
but I just wanted to show it to you, okay.
So this is the first one here,
let's say r,
parse ingredients.
Take a look at r,
and, here we go.
So we have cup, we have tsp, and we have tsp here,
but we're missing the space now,
okay, and that's because of the parentheses.
Okay, so we remove the parentheses,
and then didn't insert a new space,
but instead, we removed it completely,
and so the spaces are gone as well.
Because remember, here we also selected the space
in front and after parentheses.
And so we have to add a new space here.
Okay, so let's wait for it.
Choose this one.
Or actually, another one.
Remember it can't be the same thing,
because then it doesn't change the hash,
oh, we have an error here.
I'm not sure why.
So let's try another again, so this one.
And again, we get an error here,
that's very weird, but it still works here.
So, and so now, parsed ingredients,
and let's take a look at r, and now it should be gone.
So, yeah, so we have cup, and tsp, and cup,
and so, yeah, so the first two steps,
well for processing, are already working at this point.
And so now, really comes the hardest part,
which is to separate the numbers from the units,
from the rest of the text.
And as you can see, probably this is going to be
quite difficult, because for example, in here,
we have all of this, all of this should be the number,
then we have the unit, then we have the text.
But here, we only have this normal number,
here we don't have any number at all,
and let's take a look for example, at this example.
So let's wait for it to come back,
then we need to parse ingredients, actually,
and so here you the example where we have a number,
but no unit, but then again, some text.
And so each situation is really different,
and so we have to be prepared for all of these cases.
So basically, we have the case where we have the number,
the unit and the text,
then we have the case where we have only the number,
and just the ingredient text and no unit,
and sometimes we don't have any units and any number.
So just like in this example of,
most of these ingredients down here.
Okay,
so how are we going to do this part,
which is the most complex by far?
Well first of all, we are going to test if there is
actually a unit in the string,
and if so, where it is located.
Okay, so the first thing,
is to convert the ingredient into an array.
And I'm going to do that by splitting it,
through an empty space.
Okay, so whenever there is space,
it will now be split, and each word,
will become a new element in the array.
So we've used that here before,
and so I'm sure you're familiar with it already.
Okay, now comes the trickier part,
where we have to find the index
at which the unit is located.
Okay, so unit index,
and so how are we going to do that?
Well the first thing that comes to mind
would be to use index of,
like this, right.
But this one is not going to work,
because what we want to do is,
to find the position of the unit,
but we don't know what the unit is.
If we knew which unit we were looking for,
well then we could use index of.
So for example, if we were looking for tbsp,
if we already knew that, then we could simply ask,
which element of the array is equal to tbsp?
But it doesn't work like this in this case,
because we don't know what unit we're looking for.
Each ingredient has its own unit,
or maybe not even a unit at all.
And so what we're going to use instead, is find index.
And once more, this is an ES6 method,
that I actually already showed you in ES6 section,
but right now, we have a more real world use case for it.
Okay, so remember, into the find index function,
we actually pass in a callback function.
So for each element, which we're going to call,
element two here in this case,
because element is already taken up here.
Well basically, for each of these elements,
it will make a test, and what we want to test here,
is units dot includes,
element two.
So how does this work?
Well, includes is a brand new array method,
I think it's like an ES7 or even an ES8,
and it returns true if the element
we're passing in is in the array,
and it returns false, of course,
if the element is not in there, okay.
So what we're going to do is,
for each current element, it will test,
if that element is inside of the units array.
And what I mean here is, unit short,
so this array, with our final short unit,
and so for each of the elements in the array,
it will basically perform this test, okay.
So again, this is like a loop,
but in the case of find index,
it will return the index of the position,
where this test here turns out to be true, okay.
So let's again use the example of ounces, for example,
so it will loop over the array,
and it will only return true,
when there's an element in the array, that is ounces,
and it will then return the index in which,
this here turns out to be true, okay.
And so that's the only way to find the position
of the unit, when we don't really know,
which unit we are looking for, okay.
So this is a great trick,
and a really great use case of find index,
which is a great addition to the JavaScript language,
so it's really a cool new method on arrays.
Now as we mentioned before,
there are now several different possibilities here,
for the find index.
So let's use an if else statement,
so if unit index is greater than minus one,
this means that there is a unit.
Okay, so it if is minus one,
then it means that it couldn't find the element,
so in this case, it means that,
all of this here turned to be false.
So basically, if none of these words here,
appear in the array, so in our original string here,
then that means that this unit index,
will turn out to be minus one.
Okay, so we can actually already add that one here,
unit index,
is minus one, then that means,
there is no unit.
Okay, but actually there is another case.
Okay, so that's the case where there is no unit,
but still there is a number.
Remember, so for example, one bread,
that doesn't really need a unit,
but there is a number, and there is text, okay.
And so we assume that the number always
appears in the same position.
And so what we're going to do is to,
say array, ingredient zero, which is the first position,
then we're going to parse it to a number, an integer,
with the base of 10, remember.
And so if this is successful here,
so if it can be converted to a number,
well then this here will return the number itself,
and will therefore coerce into true here.
Okay.
There is, no unit,
but the first element is a number, okay.
So again, we're taking the first element of the array,
and we convert it to a number.
And if the conversion is successful,
well then it will return that number,
which will then coerce to true.
And if it's not a number,
then it will return not a number,
which will coerce to false.
Let me actually try to show that to you,
so let's use parse int,
with this string here.
And so it returns 234,
which is a number,
but if we had something else,
so text, well then it returns not a number,
and that will then, in turn, coerce to false,
leaving us with the third option,
which is this here.
There's no unit,
and no number, in first position.
So this one is the most straightforward case,
and so let's go ahead and start with this one.
Okay, so the first thing we're going to do,
is to create a new variable here,
and will have to be let, and not a const,
and also it has to be outside of each of these blocks here,
because again, let and const, are block scoped,
okay, and so we need to define them outside of the blocks,
and then mutate them inside of one of these blocks.
So, this is the final object that
we're actually going to return,
which is the object ingredient.
Okay, and for now, it's empty in here,
we're just like, initializing it.
So our ingredient object will always have the count,
it will have the unit,
and it will have the ingredient itself.
Now in the case that we have no unit,
while the unit is empty, I will simply say,
that it is one, because he have to put something here,
and so rather than putting, like, zero, or something,
we simply put one.
So for example, if it says tomato sauce,
without an ingredient,
well, we just say that we need one tomato sauce, okay.
And now as for the ingredient itself,
well, if there's no number, no unit,
all we really want is the entire ingredient, okay.
So that variable here, that we split it up,
right in the beginning.
So we can say ingredient, or even better,
in ES6, when we have an object that is like this,
when we say ingredient, is ingredient,
we don't need any of this,
we can simply do it like this.
So instead of having to repeat it, we just put ingredient,
and well, it will automatically then
create this property ingredient,
and assign the value to it.
In this case, this one, okay.
So, next up, we do the one where there's no unit,
but the first element is a number.
So this one is also not really hard.
So the number, we already know, is this one here,
so let's just copy it,
so count, the unit, where you don't have, again,
and then the ingredient,
well, it just the entire array, except the first element.
So the first element here is for the number,
and the rest of the array is the ingredient.
So array ingredient, then we sliced it,
and said that we only want to start at position number one,
and if we don't specify the second argument,
it goes all the way to the end, which is what we want.
And so we have now, the entire array,
except the first element.
And now we have to put all these array elements
back into a string, using of course, the join method.
Okay, so we had all of these array elements, like,
Italian, tomato and sauce,
and now we just put them back together into a string here,
with this join.
Okay, so these are the two easier cases.
Let's now test it out before we start
with the more difficult one, which is this one.
Alright, let's wait for it.
I guess it's getting,
yeah.
So,
let's take a look.
Let's r parse ingredients,
and let's take a look, and nothing really happened here,
and I know why this is happening.
It's because we didn't return the object,
but instead, we just returned the ingredient string,
so the one that we were working with,
up until point number three.
Okay, so let's do all of this again.
And you see that it already got back here,
with the recipe, so that's parsed ingredients.
And so here you see, some of these say undefined,
and that's fine, because we didn't yet
take care of the first case.
But the other ones, they now say one,
when the unit is empty, and then we have the ingredient.
And so if you compare that with the initial state,
well we see that it's exactly correct.
Right, so here we had just these strings,
and then now we have all of these objects.
Where it says always one, then unit,
and then the ingredient.
Let's see if we can do the same with another one.
So let's say, parse ingredients,
and now we actually have all of them undefined,
except the last one, okay.
So let's take this one here as an example to see
what we have to, to do next.
So you see that for example here,
the unit is the third element of the array, right.
So the first element will be 1/4,
and then the second element will be just 1/2,
and then the third element will be the cups.
But then in this case, in number two,
well the first one is the number,
and then already the second one is the unit, okay.
And so what we will do is assume that everything
that comes for a unit will always be the number.
Okay, so in this case, we will say that 4 1/2,
will be the number, and then after that comes the unit.
Okay, so let's implement what I just said.
So const,
I'm going to call this one here array count,
is in array ingredients slice,
from the beginning until the unit index, excluding.
Okay, so if the index is number two,
well that means that position zero and one,
will be for the count, okay.
So just like in the last example,
where 1 1/2 were the first two positions,
so these two are the part of the count.
Let me write that down here actually.
Example 4 1/2 cups,
our count will be 4 1/2.
Okay, and now we need to figure out,
a number out of these values here, okay.
Now let's actually get this here,
and I will put another example,
because there can be, of course different example,
so if it was four cups, well then our count,
is just four, right.
And so we have different situations here.
So you see that this is getting quite complex,
and of course, this is just a great exercise to think,
so it's not really important that you memorize
how you can parse recipe ingredients.
But it's important that you understand
the thought process that you go through,
in order to figure out how to
accomplish the goal that you have.
In this case, well it's parsing our ingredients
into a, that we defined initially, okay.
And so we use the tools that we have,
in order achieve a goal that we established.
And that's what coding is all about,
okay, so that's what I want you to understand.
It's not really memorizing that it want you to do,
it's just understanding how we can use
these different tools to achieve exactly what we need.
So again, we have these two cases here,
where there's more than two elements before the unit,
and also the case where we have just one number.
And in this case, it's really simple.
So let's say, if,
our count dot length,
which is what defines how many elements
there are before the unit.
So if it's just one,
then the count is array inc, zero.
And actually I have to define the count before,
so just the situation that we had before,
so defining it outside of the block.
Okay, so if there's only one element before the unit,
well then that element is of course the number itself.
So the count is then array inc zero.
And that's not yet the final story,
but for now, let's assume that this is how it works.
Now if we have more than one number,
which is usually like, something like this,
so 4 1/2, or 1 2/3, something like this,
well then we have to do it differently.
And so now I'm going to show you the eval function,
that I mentioned before.
So what we're going to do is to basically join
these two strings,
because they are strings in this array here, okay.
We're never talking about numbers,
it's really just strings.
So we're going to join these two strings using a plus sign,
and then do something called evaluate the string.
Okay, so I'm going to explain to you,
how and why,
so the array of ingredient,
dot slice, from the beginning,
until the unit index.
Right, so on these first elements,
we are going to join them,
using the plus sign,
and we will then evaluate,
whatever is the result of that.
Okay, and we wouldn't have to do it like this,
but this is just a great opportunity to,
to show you this function here,
that you might encounter someday
when you're looking at some JavaScript code, okay.
So this one here, for example,
well, turns out to be string,
four plus, 1 1/2.
Okay, and eval will then do is it will evaluate
this string here as being a JavaScript code.
And so it will do the math here,
and calculate 4.5.
Okay, so if we do eval of this,
well this will then turn out the be 4.5, okay.
So does this way of calculating here makes sense to you?
Now this is almost done now,
there's just one edge case that we also need to talk about.
Which is what happens in this recipe here.
So, let's wait for it.
So you see here in ingredients,
that some of them, they have this dash,
so instead of being 1 1/3,
it's one minus 1/3,
but it really mean one plus 1/3.
So it's 1 1/2 here, for example,
not one minus 1/2, okay,
and so that is actually not good.
Because none of cases currently covers this.
But what we could do here is,
to simply replace this minus with this plus,
and then evaluate that string as well,
just like we did before.
Okay, and so that's actually pretty easy,
all we have to do here is to replace,
the minus with a plus.
And then finally, of course,
say eval like this.
Okay, so if there is a minus,
then it will simply be replaced with a plus,
and then the string will be evaluated,
in order to return the correct number.
Okay, so all we have to do is to recreate this object here,
so our final ingredient object.
Ooh, so this is really a long lecture here,
and there's a lot to do,
and it could be even more complete,
so there are still some edge cases,
which are not going to really work.
But I think this is more than enough,
for what we're trying to do here, okay.
So our count will be our count,
so this is the same case as before here,
with the ingredient.
We don't need to specify count, equal to count,
because, yeah, we already have this variable here,
with that name.
So next up, we have the unit.
Which is located at array of ingredient, at unit index.
Okay.
And then finally, we have the ingredient,
which is also in array ingredient dot slice,
and so we want to select the part of the array,
and it starts right after the unit.
So at unit index, plus one,
all the way until the end, okay.
And we then want to join this of course,
back into a string.
And alright, that should actually be it.
So that was a lot of work,
let's test if it, if it's going to work.
So let's get rid of this here,
we don't need this testing.
And also, where's the other one?
And of course also, this pizza here.
So let's get rid of all of this,
and then what we want to do here,
before display the recipe,
we also want to parse the ingredients.
So let's say n parse ingredient,
and so we want state, dot recipe, dot parse,
ingredients.
So, let's take a look now,
and it should be fetching our recipe here now.
And indeed.
And so now we have all of our units here,
and it's actually working you see.
So we had 1 1/3, I remember here,
and now it's just a number, 1.333,
which is the exact result of that.
Now this part here doesn't really look right,
so shortening,
and then the rest seems kind of cut off,
so,
let's actually try to log to the console here,
the ingredients without being processed.
So console,
dot log,
state dot recipe,
dot ingredient.
And so, here are the results,
and actually it's, it's correct,
so it's shortening it,
and then may substitute butter.
Okay, so I'm not really sure what this is here,
maybe some of your will know what that actually means, okay.
But anyway, it looks like this is kind of correct.
So let's test it on a couple more results here.
So let's take a look at this one.
And I'm not sure if it did come back,
oh yeah.
I guess I just clicked on the same one
that was already active.
And so take a look,
and yeah, great.
So we had 4 1/2 cups, and it was converted to 4 1/2,
so perfect, this is perfect, it really works.
So that's just amazing.
Let's take a look at this one,
I remember that this one here,
was a bit different from the other ones,
but it should still be working.
And,
indeed.
Yeah, it looks fantastic, so,
I think we're really done here now,
after a long lecture of writing all this code.
And maybe this was not even the perfect code,
so everyone will have different ways
of achieving the same result.
But I hope that this kind of made sense to you,
and if not, then just go a bit through the code,
by yourself, and try to really understand what happens here.
For example, this part here,
I find it a bit tricky here maybe to understand,
and so try to go ahead and figure everything out,
on your own, that doesn't really make sense.
Okay, anyway, take a break now,
and see you in the next video, when you're ready for it.