I did find an issue in your final code which you posted:
When you iterate over the array, you use this conditional here: if (i !== j && num !== nums[i - 1])
This will instantly fail. On the first iteration, i=0, therefore nums[i-1] is immediately OOB.
You can use a proxy in JS to allow negative indices fwiw.
Also, i will never equal j.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I loved your thorough explanation!
I did find an issue in your final code which you posted:
When you iterate over the array, you use this conditional here:
if (i !== j && num !== nums[i - 1])
This will instantly fail. On the first iteration,
i=0
, thereforenums[i-1]
is immediately OOB.You can use a proxy in JS to allow negative indices fwiw.
Also,
i
will never equalj
.