Fix ternary operator bug from previous commit in sortperm for ranges (#2160)