Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Sorting - JavaScript

RSS
Modified on Thu, Sep 01, 2011, 4:49 PM by Administrator Categorized as JavaScript, jQuery, and Angular
function onButtonClick() {
    var fruits = ['Banana', 'Orange', 'Apple', 'Mango'];
    alert(fruits.sort(sortDescending));
}
function sortAscending(a, b){
    if (a == b) return 0;	
    if (a > b) return 1;	
    return -1;
}
function sortDescending(a, b){
    return -1 * sortAscending(a, b);
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.