Skip to content Skip to sidebar Skip to footer

How To _prevent_ Divs From Appearing In Random Order

Okay, so I'm learning front-end dev with javascript/jquery/bootstrap through FreeCodeCamp. This is not a core part of the project, but I don't understand it and it's distracting me

Solution 1:

You need to return -1, 0 or 1 based on the condition for proper sorting.

function sortMe(a, b) {
     return a.className.localeCompare(b.className);
} 

For better browser support use,

function sortMe(a, b) {
     return a.className < b.className ? 1 : -1;
} 

Post a Comment for "How To _prevent_ Divs From Appearing In Random Order"