You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think that this assertion function is comparing the array 'a' with the each elements of array 'b'.
So, I tried that the arguments [1], [1], [1] give to function is. The result was false.
I think that the result is true in this case.
Please tell me why this assertion function 'is' is correct?
I read this book in Japanese. If the translation is not good, could you tell me the sentences of the exercise 5 in English?
The text was updated successfully, but these errors were encountered:
Hey there! This example may be a little confusing -- is performs a shallow comparison, but the example might make it seem like we actually want a deep comparison.
This should work, since we're checking that each argument references the same value (it does):
This wouldn't work, because each array we pass in is a brand new reference:
console.log(is([1,2],[1,2],[1,2]))// false
You could, of course, extend is to perform a deep comparison (let's call it looksLike). Want to try implementing it? Once you're done, it should work like this:
function is<T>(
a: T,
...b: [T, ...T[]]
): boolean {
let c
for(let i = 0; i < b.length; i++) {
c = JSON.stringify(a) === JSON.stringify(b[i])
return c
}
return c !== undefined ? c : false
}
I think that this assertion function is comparing the array 'a' with the each elements of array 'b'.
So, I tried that the arguments
[1], [1], [1]
give to function is. The result was false.I think that the result is true in this case.
Please tell me why this assertion function 'is' is correct?
I read this book in Japanese. If the translation is not good, could you tell me the sentences of the exercise 5 in English?
The text was updated successfully, but these errors were encountered: