p5.js
p5.js copied to clipboard
Fix the Array Comparison bug in outputs.js
Signed-off-by: nikhilkalburgi [email protected]
Resolves: #6660
PR Checklist
- [x]
npm run lintpasses - [ ] [Inline documentation] is included / updated
- [ ] [Unit tests] are included / updated
Hi @ayushanand308, What if we sort them and check?
JSON.stringify(this.ingredients.shapes[f].slice().sort()) !== JSON.stringify([include].slice().sort())
This will create a copy , sort then stringify to compare
@nikhilkalburgi That will be very inefficient and considering this will run on every frame, may significantly impact performance if the drawings get complex enough.
Hi @limzykenneth, Do you think that the initial condition is necessary as it always returns true? How can it get resolved?
In the subsequent for loop there is already a check for existence of the element in the list so the check before that is either not needed (ie. be an else instead of else if or be something that can be completed very quickly. I think for this case not having that earlier check should be fine and is how is has worked until now effectively. The loop can be optimized a bit by breaking early as well.
maybe here we can use isEqual function of lodash library to compare them.