JSFiddle - React, Tailwind, and code Playground

by xavierm02

JavaScript

function listen( constructor, items ) {
    var prototype = constructor.prototype;
    var valueOf = prototype.valueOf;
    var length = items.length;
    var values = [ ];
    prototype.valueOf = function ( ) {
        var value = 1 << ( items.indexOf( this ) );
        values.push( value );
        return value;
    };
    return function ( value ) {
        prototype.valueOf = valueOf;
        values.push( value );
        return values;
    };
}


function Item( v ) { this.v = v; }
var n = 4;
var items = [ ];
var i = 0;
while ( i++ < n ) {
    items.push( new Item( i ) );
}

var combinaisons = [ 'items[0]' ];
for ( i = 1; i < n; ++i ) {
    combinaisons = combinaisons.map( function ( combinaison ) {
        return combinaison + ' & items[' + i + ']';
    } ).concat( combinaisons.map( function ( combinaison ) {
        return combinaison + ' | items[' + i + ']';
    } ) );
}

combinaisons.forEach( function ( combinaison ) {
    console.log( combinaison, listen( Item, items )( eval( combinaison ) ) );
} );