# A problem about sorting final result

Three days ago, I asked a question about B-Spline Basis fuction here

@Michael E2 given a solution to make the order of interval looks normal

The easiest way would be to sort it afterwards: MapAt[SortBy[Last], piecewisefn, 1], piecewisefn is the result of NBSpline. (Use SortBy[#, Last] & instead of SortBy[Last] if you're using V9 or earlier.)

Trial 1

 sortResult[res_] := MapAt[SortBy[#, Last] &, res, 1] /; res != 0
sortResult := 0;
knots={1, 2, 2, 4, 5, 7};
sortResult[NBSpline[1, 2, u, knots]] Trial 2

 NBSpline[1, 3, u, {1, 2, 2, 4, 5, 7}]// MapAt[SortBy[#, Last] &, #, 1] & This time, it gives me a normal order $$2 \leq u <4, 4 \leq u <5, 5 \leq u <7$$

### Question:

• Do you get the desired result if you change the last line of Trial 1 to tmp = NBSpline[1, 2, u, knots]; sortResult[tmp]; tmp? – kglr Oct 18 '14 at 7:43
• @kguler, it didn't sort the $interval$. – xyz Oct 18 '14 at 7:47

I hope I understand your question. I think you are wondering why Trial 1 does not work the same as Trial 2. In that case the answer lies with != or Unequal. The Condition will not match because != does not evaluate when one side is symbolic and the other numeric. Instead you should use:
sortResult[x_ /; x == 0] := 0;

The first definition will catch all arguments Equal to zero. See: