-
-
Save apaleslimghost/e55ee43667a42f3e8cdc to your computer and use it in GitHub Desktop.
Revisions
-
kangax revised this gist
Oct 6, 2015 . 1 changed file with 6 additions and 14 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,7 @@ /* 1) passing array > quicksort([4,3,2,1]); // => [1,2,3,4] */ function quicksort(tail) { if (tail.length === 0) return []; let head = tail.splice(0, 1)[0]; @@ -15,15 +11,11 @@ function quicksort(tail) { } /* 2) via arguments > quicksort(4,3,2,1); // => [1,2,3,4] or: > quicksort(...[4,3,2,1]); // => [1,2,3,4] */ function quicksort(x, ...xs) { if (arguments.length === 0) return []; return quicksort(...xs.filter( _ => _ <= x)) -
kangax renamed this gist
Oct 6, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
kangax renamed this gist
Oct 6, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
kangax revised this gist
Oct 6, 2015 . 1 changed file with 32 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ /* passing array quicksort([4,3,2,1]); // => [1,2,3,4] */ function quicksort(tail) { if (tail.length === 0) return []; let head = tail.splice(0, 1)[0]; return quicksort(tail.filter( _ => _ <= head)) .concat([head]) .concat(quicksort(tail.filter( _ => _ > head ))) } /* via arguments quicksort(4,3,2,1); // => [1,2,3,4] or: quicksort(...[4,3,2,1]); // => [1,2,3,4] */ function quicksort(x, ...xs) { if (arguments.length === 0) return []; return quicksort(...xs.filter( _ => _ <= x)) .concat([x]) .concat(quicksort(...xs.filter( _ => _ > x ))) } -
kangax renamed this gist
Oct 6, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
kangax created this gist
Oct 6, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ quicksort :: (Ord a) => [a] -> [a] quicksort [] = [] quicksort (x:xs) = let smallerSorted = quicksort (filter (<=x) xs) biggerSorted = quicksort (filter (>x) xs) in smallerSorted ++ [x] ++ biggerSorted