Comparing two arrays

Here is my code: https://codepen.io/lukakuwu/pen/zYyPYRm?editors=0010 I have an array with prices and a function to add the tax. I made a second array with the expected results and used jest to test. I know theres something wrong with how im calling the results arrays values but I dont know how to fix it. The tests should pass through the array dishes twice and compare all of the items in the array results with the price. Maybe theres a better way to reformat it but Ive tried everything I can think of
No description
5 Replies
ἔρως
ἔρως16mo ago
you can't compare arrays when you compare an array to another, you're effectively checking if it is the same instance or not since they are 2 different instances, they will always be different
ἔρως
ἔρως16mo ago
Expect · Jest
When you're writing tests, you often need to check that values meet certain conditions. expect gives you access to a number of "matchers" that let you validate different things.
ἔρως
ἔρως16mo ago
if you want to make sure that the array is EXACTLY the same, aparently you can sort both arrays
ἔρως
ἔρως16mo ago
Stack Overflow
Is there an Array equality match function that ignores element posi...
I get that .toEqual() checks equality of all fields for plain objects: expect( {"key1":"pink wool","key2":"diorite"} ).toEqual( {"key2":&q...
ἔρως
ἔρως16mo ago
you can also use JSON.stringify() and compare the result (which will be picky about the order of the elements)
Want results from more Discord servers?
Add your server