DynkanMaclaud,
<script>
function fn(a, b) {
a = a.slice(0).sort(function(a, b) {
return b - a
}).filter(function(a) {
var c = 0 < b;
b -= a;
return 0 < c
});
return 0 < b ? !1 : a
};
document.write(JSON.stringify(fn([2, 5, 9, 11, 1, 2, 4],12)));
</script>