I couldn’t resist testing this using the following code:
// $temp_c:=$temp_c.push($n) // #1
// $temp_c:=$temp_c.push($n).distinct() // #2
If ($temp_c.indexOf($n)<0) // #3
ALERT(“This run: “+String($ms)+” ms”)
For Code :
use your own random range method.
#1 case I simply pushed $n to get a base line.
#2 case is Vincent’s approach
#3 case is the if statement
My results were:
push only: 12-16 ms
push & distinct: 24-30 ms
if indexOf: 14-16 ms
This is v18.1, interpreted on a 2016 MBP.
First thought is these differences may disappear when compiled.
Second is the one-liner is technically slower by a few milliseconds - when I do it 1000 times.
My conclusion: the one liner is the way to go. The difference in run time is inconsequential in all but the most extreme circumstances.