lib/Sort Array of Objects by Property Values.js
// program to sort array by property name
program to sort array by property name
program to sort array by property name
function compareName(a, b) {
    const name1 = a.name.toUpperCase();
    const name2 = b.name.toUpperCase();
    let comparison = 0;
    if (name1 > name2) {
        comparison = 1;
    } else if (name1 < name2) {
        comparison = -1;
    }
    return comparison;
}
function compareName ( a , b ) { const name1 = a . name . toUpperCase ( ) ; const name2 = b . name . toUpperCase ( ) ; let comparison = 0 ; if ( name1 > name2 ) { comparison = 1 ; } else if ( name1 < name2 ) { comparison = - 1 ; } return comparison ; }
program to sort array by property name
program to sort array by property name
// converting to uppercase to have case-insensitive comparison