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