Javascript for fun: Combinations

Dimitris Moutsatsos
1 min readJul 10, 2020

I had a small request to display all the true/false combinations.
The only catch was that 2 vars cannot be true,true or false,false .

So ..

var totalCombinatinations=0;
for (let i = 0; i < 1 << 5; i++) {
if (!(!!(i & (1<<3))==!!(i & (1<<2))) ) {
console.log([!!(i & (1<<4)),!!(i & (1<<3)),!!(i & (1<<2)), !!(i & (1<<1)), !!(i & 1)]); totalCombinatinations++;
}
}
console.log("Total Combinatinations: "+totalCombinatinations);

You can try it on your browser console or just in a simple nodejs

--

--

Dimitris Moutsatsos

developer and weirdo / current: FinTech Insights / Tychetech / Resitech