/*
TinyTableV3 ソート実装の修正案1 (Google Chrome 7 でソートされないバグを修正)
*/
function cp (string1, string2) {
var result, number1, number2;
string1 = String(string1).toLowerCase().replace(/^\s+|\s+$/g, '');
string2 = String(string2).toLowerCase().replace(/^\s+|\s+$/g, '');
if (string1 === string2) {
return 0;
} else if (string1 > string2) {
result = 1;
} else {
result = -1;
}
number1 = parseFloat(string1.replace(/[,$]/g, ''));
number2 = parseFloat(string2.replace(/[,$]/g, ''));
if (!isNaN(number1) && !isNaN(number2) && number1 !== number2) {
if (number1 > number2) {
return 1;
} else if (number1 < number2) {
return -1;
}
}
number1 = Date.parse(string1);
number2 = Date.parse(string2);
if (!isNaN(number1) && !isNaN(number2) && number1 !== number2) {
if (number1 > number2) {
return 1;
} else if (number1 < number2) {
return -1;
}
}
return result;
}
function format_array (array) {
return '["' + array.join('", "') + '"]';
}
print(format_array(['11f', '11e', '13a', '12b'].sort(cp)));
print(format_array(['11/3', '12/c', '12/a', '11/5', '11/2'].sort(cp)));
print(format_array(['12/01/1981', '02/14/1990', '03/29/1970', '12/02/1962'].sort(cp)));
print(format_array(['41%', '55%', '6%', '81%'].sort(cp)));
print(format_array(['-1', '-10', '1', '5', '-7', '6'].sort(cp)));
print(format_array(['February 25, 2001', 'April 30, 2003', 'July 23, 2005', 'June 22, 2004', 'April 27, 2002'].sort(cp)));
print(format_array(['a1b', 'a1a', 'a', 'a2', 'a0', 'a20', 'a10', 'a1'].sort(cp)));
print(format_array(['rfc1.txt', 'rfc2086.txt', 'rfc822.txt'].sort(cp)));
LyoKICAgVGlueVRhYmxlVjMg44K944O844OI5a6f6KOF44Gu5L+u5q2j5qGIMSAoR29vZ2xlIENocm9tZSA3IOOBp+OCveODvOODiOOBleOCjOOBquOBhOODkOOCsOOCkuS/ruatoykKKi8KCmZ1bmN0aW9uIGNwIChzdHJpbmcxLCBzdHJpbmcyKSB7CiAgdmFyIHJlc3VsdCwgbnVtYmVyMSwgbnVtYmVyMjsKCiAgc3RyaW5nMSA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ewogIHJldHVybiAnWyInICsgYXJyYXkuam9pbignIiwgIicpICsgJyJdJzsKfQoKcHJpbnQoZm9ybWF0X2FycmF5KFsnMTFmJywgJzExZScsICcxM2EnLCAnMTJiJ10uc29ydChjcCkpKTsKcHJpbnQoZm9ybWF0X2FycmF5KFsnMTEvMycsICcxMi9jJywgJzEyL2EnLCAnMTEvNScsICcxMS8yJ10uc29ydChjcCkpKTsKcHJpbnQoZm9ybWF0X2FycmF5KFsnMTIvMDEvMTk4MScsICcwMi8xNC8xOTkwJywgJzAzLzI5LzE5NzAnLCAnMTIvMDIvMTk2MiddLnNvcnQoY3ApKSk7CnByaW50KGZvcm1hdF9hcnJheShbJzQxJScsICc1NSUnLCAnNiUnLCAnODElJ10uc29ydChjcCkpKTsKcHJpbnQoZm9ybWF0X2FycmF5KFsnLTEnLCAnLTEwJywgJzEnLCAnNScsICctNycsICc2J10uc29ydChjcCkpKTsKcHJpbnQoZm9ybWF0X2FycmF5KFsnRmVicnVhcnkgMjUsIDIwMDEnLCAnQXByaWwgMzAsIDIwMDMnLCAnSnVseSAyMywgMjAwNScsICdKdW5lIDIyLCAyMDA0JywgJ0FwcmlsIDI3LCAyMDAyJ10uc29ydChjcCkpKTsKcHJpbnQoZm9ybWF0X2FycmF5KFsnYTFiJywgJ2ExYScsICdhJywgJ2EyJywgJ2EwJywgJ2EyMCcsICdhMTAnLCAnYTEnXS5zb3J0KGNwKSkpOwpwcmludChmb3JtYXRfYXJyYXkoWydyZmMxLnR4dCcsICdyZmMyMDg2LnR4dCcsICdyZmM4MjIudHh0J10uc29ydChjcCkpKTs=
["11e", "11f", "12b", "13a"]
["11/2", "11/3", "11/5", "12/a", "12/c"]
["02/14/1990", "03/29/1970", "12/02/1962", "12/01/1981"]
["6%", "41%", "55%", "81%"]
["-10", "-7", "-1", "1", "5", "6"]
["February 25, 2001", "April 27, 2002", "April 30, 2003", "June 22, 2004", "July 23, 2005"]
["a", "a0", "a1", "a10", "a1a", "a1b", "a2", "a20"]
["rfc1.txt", "rfc2086.txt", "rfc822.txt"]