September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,33 +1,31 @@
(function () {
(() => {
'use strict';
// QUICKSORT --------------------------------------------------------------
// quickSort :: (Ord a) => [a] -> [a]
function quickSort(xs) {
if (xs.length) {
var h = xs[0],
[less, more] = partition(
x => x <= h,
xs.slice(1)
);
const quickSort = xs =>
xs.length > 1 ? (() => {
const
h = xs[0],
[less, more] = partition(x => x <= h, xs.slice(1));
return [].concat.apply(
[], [quickSort(less), h, quickSort(more)]
);
})() : xs;
} else return [];
}
// GENERIC ----------------------------------------------------------------
// partition :: Predicate -> List -> (Matches, nonMatches)
// partition :: (a -> Bool) -> [a] -> ([a], [a])
function partition(p, xs) {
return xs.reduce((a, x) => (
a[p(x) ? 0 : 1].push(x),
a
), [[], []]);
}
const partition = (p, xs) =>
xs.reduce((a, x) =>
p(x) ? [a[0].concat(x), a[1]] : [a[0], a[1].concat(x)], [
[],
[]
]);
// TEST -------------------------------------------------------------------
return quickSort([11.8, 14.1, 21.3, 8.5, 16.7, 5.7]);
})();