What is the problem with this array sorting?
var arr = ["Q1#2013#A", "Q1#2013#B", "Q1#2014#A", "Q1#2014#B", "Q2#2013#A", "Q2#2013#B", "Q2#2014#A", "Q2#2014#B", "Q3#2013#A", "Q3#2013#B", "Q4#2013#A", "Q4#2013#B"];
arr.sort(function(a, b) {
var s = a.split('#'), t = b.split('#');
var c = s.pop(), d = t.pop();
s1 = s.reverse().join('#')+'#'+c, s2 = t.reverse().join('#')+'#'+d;
return s1 > s2;
});
It returns the following output:
["Q2#2014#A", "Q1#2013#A", "Q1#2013#B", "Q2#2013#A", "Q2#2013#B", "Q3#2013#A", "Q3#2013#B", "Q4#2013#A", "Q4#2013#B", "Q1#2014#A", "Q1#2014#B", "Q2#2014#B"]
The ideal result should be:
["Q1#2013#A", "Q1#2013#B", "Q2#2013#A", "Q2#2013#B", "Q3#2013#A", "Q3#2013#B", "Q4#2013#A", "Q4#2013#B", "Q1#2014#A", "Q1#2014#B", "Q2#2014#A", "Q2#2014#B"]