Node.js examples for Algorithm:Sort
Sort Array in alphabetical order
// TODO: integrate sorting methods in a much cleaner way var FSort = {/*from www .j a va 2 s . c om*/ /** * * sort Array in alphabetical order * * http://www.brain4.de/programmierecke/js/arraySort.php * */ alphabetical: function(a, b) { /* var A = a.toLowerCase(); var B = b.toLowerCase(); if (A < B) return -1; else if (A > B) return 1; else return 0; */ a = a.toLowerCase(); a = a.replace(/?/g,'a'); a = a.replace(/?/g,'o'); a = a.replace(/?/g,'u'); a = a.replace(/?/g,'s'); b = b.toLowerCase(); b = b.replace(/?/g,'a'); b = b.replace(/?/g,'o'); b = b.replace(/?/g,'u'); b = b.replace(/?/g,'s'); return(a == b) ? 0 : (a>b) ? 1 : -1; }, /** * * sort array by distance of object from center of canvas * */ distanceToCenter: function(a, b) { var valueA = a.getDistanceToCenter(); // console.log( valueA ); var valueB = b.getDistanceToCenter(); // console.log( valueB ); var comparisonValue = 0; if (valueA > valueB) comparisonValue = -1; else if (valueA < valueB) comparisonValue = 1; return comparisonValue; } };