Easy way to compare arrays?
See original GitHub issueI tried
const array: f64[] = [20.0,30.0,0,0,0,0]
expect<f64[]>(array).toBe([20.0,30.0,0,0,0,0])
which may not even be the same types of array, but I realized that this compares them by reference (obviously it would fail).
Is there an API to easily compare arrays? Or should I loop on the indexes and use expect on each value for now?
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
How to compare arrays in JavaScript? - Stack Overflow
To compare arrays, loop through them and compare every value: Comparing arrays: // Warn if overriding existing method if(Array.prototype.equals) ...
Read more >Compare Two Arrays in Java - GeeksforGeeks
A simple way is to run a loop and compare elements one by one. Java provides a direct method Arrays.equals() to compare two...
Read more >Comparing Arrays in JavaScript - freeCodeCamp
A better approach would be to compare the array's length and then loop through and compare each element of the array. Method 1:...
Read more >How do I compare two arrays in JavaScript?
Learn how you can compare two arrays in JavaScript using various different techniques.
Read more >How to compare two arrays in Java? - Tutorialspoint
Using Arrays.equals(array1, array2) methods − This method iterates over each value of an array and compare using equals method.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I haven’t closed this issue because I want to enable array of references comparisons.
Since we cannot get the programmatic offset of the child type, we cannot use memcompare because we need the size of the block. We can only opt into block comparisons for strings and array buffers and access their size at runtime. This will be supported in the 1.1.0 release.
Once
typeof
support exists in the compiler, we will enable regular reference comparisons.In 1.1.0 they will default to
==
comparisons, which can be overridden using@operator("==")
. This does not help people who want to use portable code, but aspect is burgeoning and I don’t mind enabling support for this later.I’m still fumbling around, f.e. https://github.com/AssemblyScript/assemblyscript/issues/645