JSFiddle - React, Tailwind, and code Playground
by rodneyrehm
HTML
<!--
write about how to cache the values for comparison, so they don't have to be recalculated over and over again
-->
JavaScript
var list = ['a', 'c', 'b', 'd', 'b', 'x', 'b'],
comparisons = 0;
list.sort(function(a, b) {
comparisons++;
return a > b ? 1 : -1;
});
console.log(list.join(','), "took", comparisons, " comparisons to sort");