So if you have an array of numbers:
var arr = [2, 25, 37, 54, 54, 76, 88, 91, 99]
First filter the array to just that which is less than 100
var filtered = arr.filter(function(val){ return val < 100; });
Now you need to find the power set of those numbers.
It looks like there's a sample of code here that will accomplish that.
Excerpt
function powerset(arr) {
var ps = [[]];
for (var i=0; i < arr.length; i++) {
for (var j = 0, len = ps.length; j < len; j++) {
ps.push(ps[j].concat(arr[i]));
}
}
return ps;
}
So you'd take
var powerSet = powerset(filtered);
And as some sugar, you could format the result nicely with join
console.log('{' + powerSet.join('}{') + '}');
or if you really want it output as a set of all sets, this would technically be more correct :)
console.log('{ {' + powerSet.join('}{') + '} }');
Here's a WORKING DEMO
EDIT
Sorry, you want the set of all sets whose sum is less than 100. kennebec is right. Ditch the filtering first step, and then modify the powerset method thus, using reduce to quickly see if an array's sum is less than 100:
function powerset(arr) {
var ps = [[]];
for (var i=0; i < arr.length; i++) {
for (var j = 0, len = ps.length; j < len; j++) {
var arrCandidate = ps[j].concat(arr[i]);
if (arrCandidate.reduce(function(p, c){ return p + c; }) < 100)
ps.push(arrCandidate);
}
}
return ps;
}
Here's an UPDATED DEMO