Last active
August 29, 2015 14:26
-
-
Save davatron5000/aa124219766fe9ad62de to your computer and use it in GitHub Desktop.
southwestSort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var letters = ["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]; | |
function southwestSort( arr ) { | |
var a = arr.slice( 0, Math.floor(arr.length / 3) ); | |
var b = arr.slice( Math.floor(arr.length / 3), Math.floor(arr.length / 3)*2 ); | |
var c = arr.slice( Math.floor(arr.length / 3)*2, arr.length ); | |
return a.sort().concat(b.sort()).concat(c.sort()); | |
} | |
southwestSort( letters ); | |
// [ "e","i","q","r","t","u","w","y","a","d","f","g","h","o","p","s","b","c","j","k","l","m","n","v","x","z" ] |
this function smells as bloated as american airlines, dave.
function southwestSort(a){return a.concat.apply([],[0,1,2].map(function(i){return a.slice(i*a.length/3,++i*a.length/3,).sort()}))}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fun fact: This is how the Dvorak keyboard was invented.