JortSort
jortSort is a sorting toolset that makes the user do the work and guarantees efficiency because you don't have to sort ever again. It was originally presented by Jenn "Moneydollars" Schiffer at the prestigious JSConf.
jortSort is a function that takes a single array of comparable objects as it's argument. It then sorts the array in descending order and compares the sorted array to the originally provided array. If the arrays match (i.e. the original array was already sorted), the function returns true. If the arrays do not match (i.e. the original array was not sorted), the function returns false.
JavaScript
The original JavaScript implementation courtesy of the author, Jenn "Moneydollars" Schiffer. <lang javascript>var jortSort = function( array ) {
// sort the array var originalArray = array.slice(0); array.sort( function(a,b){return a - b} );
// compare to see if it was originally sorted for (var i = 0; i < originalArray.length; ++i) { if (originalArray[i] !== array[i]) return false; }
return true;
};</lang>
Swift
<lang Swift>func jortSort<T:Comparable>(inout array: [T]) -> Bool {
// sort the array let originalArray = array array.sort({$0 < $1}) // compare to see if it was originally sorted for var i = 0; i < originalArray.count; ++i { if originalArray[i] != array[i] { return false } } return true
}</lang>