fork download
  1. function sortWithFilter (pred, list) {
  2. if (!list.length) return [];
  3. var head = list.shift(), tail = list;
  4. var lesser = tail.filter(function (e) { return e <= head; });
  5. var greeter = tail.filter(function (e) { return e > head; });
  6. return sortWithFilter(pred, lesser).concat(pred(head) ? [head] : []).concat(sortWithFilter(pred, greeter));
  7. }
  8.  
  9. var a = [1,2,3,7,4,1,6,7,4,3,2,-3,-7,123];
  10. var f = function (e) { return e > 0; };
  11.  
  12. console.log(sortWithFilter(f, a));
Runtime error #stdin #stdout 0.02s 4980KB
stdin
Standard input is empty
stdout
Standard output is empty