Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                class SetHelper extends Set {
    /**
     * 验证集合是否为有效集合
     * @param {*} set
     * @returns
     */
    _isValid = (set) => {
        return set && set instanceof Set && set.size > 0;
    };

    union(set) {
        if (!this._isValid(set)) return new SetHelper();
        return new SetHelper([...this, ...set]);
    }

    difference(set) {
        if (!this._isValid(set)) return new SetHelper();
        const differenceSet = new SetHelper();
        this.forEach((item) => {
            !set.has(item) && differenceSet.add(item);
        });
        return differenceSet;
    }

    intersection(set) {
        const intersectionSet = new SetHelper();
        if (!this._isValid(set)) return intersectionSet;
        const [smallerSet, biggerSet] =
            set.size <= this.size ? [set, this] : [this, set];
        smallerSet.forEach((item) => {
            biggerSet.has(item) && intersectionSet.add(item);
        });
        return intersectionSet;
    }

    intersectionDifference(set) {
        if (!this._isValid(set)) return new SetHelper();
        return new SetHelper([
            ...this.difference(set),
            ...set.difference(this),
        ]);
    }

    isSubset(set) {
        if (!this._isValidSet(set)) return false;
        return (
            this.size <= set.size && [...this].every((item) => set.has(item))
        );
    }

    isSuperset(set) {
        if (!this._isValidSet(set)) return false;
        return (
            this.size >= set.size && [...set].every((item) => this.has(item))
        );
    }
}

class StaticSet extends SetHelper {
    constructor(items) {
        super(items);

        this.add = undefined;
        this.delete = undefined;
        this.clear = undefined;
    }
}

const setA = new StaticSet(new Set([1, 2, 3, 4]));
const setB = new StaticSet(new Set([3, 4, 5, 6]));
console.log([...setA.union(setB)]); // [ 1, 2, 3, 4, 5, 6 ]
console.log([...setA.difference(setB)]); // [ 1, 2 ]
console.log([...setA.intersection(setB)]); // [ 3, 4 ]
console.log([...setB.intersectionDifference(setA)]); // [ 5, 6, 1, 2 ]

              
            
!
999px

Console