trying to attempt learn more about the new javascript syntax and came across this.
a.find(c=>!(a[-c]^=1))
I would very much appreciate it if someone could expand this out and explain the syntax for me.
For more clarity.
the array is a set of integers. The goal is to find the first duplicate in the set.
ie. if a = [1,2,4,5,4,1]
the function should return 4
a.find(c=>!(a[-c]^=1))
the above is the part of the function which finds first duplicate.
- specifically what i don't understand is how -c which is negative of the value in the set is helping not return undefined all the time since there is never a negative index in the array.
- a[-c]^=1 is some for of comparison that i'm not familiar with so an example of it's concept or a link to docs would be much appreciated.
- why is it evaluated with 1 Thank You.