Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re^2: Trudging along the learning perl path.by vrk (Chaplain) |
on Apr 18, 2017 at 13:05 UTC ( [id://1188211]=note: print w/replies, xml ) | Need Help?? |
That's cheating a bit, because it only works with arrays of nonnegative integers. The OP version works with any numeric elements (<=> comparison). Interesting angle nonetheless. The hashless solution doesn't actually need any sorting. The following is a brute force filter, which maintains the input order of elements:
It's of course asymptotically slower than sorting (O(n**2) vs O(n*log(n))), but if the input happens to be mostly duplicates, it will be faster in practice.
In Section
Seekers of Perl Wisdom
|
|