Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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

              
                // Array & Set

// test cases
const a = [1, 2, 3, 1];
const b = [2, 3, 4, 2];
const c = ['x', 1, 'z'];

// union (unique)
const union = (a1, a2) => [...new Set(a1.concat(a2))];
// Note: [...new Set(a1, a2))] works for same type, failed with [1], ['x']
// Use Set only to dedupe, and use Array for manipulation

// intersection (unique)
const intersection = (a1, a2) => [...new Set(a1.filter(x => a2.includes(x)))];

// minus: a1 - a2 (unique)
const minus = (a1, a2) => [... new Set(a1.filter(x => !a2.includes(x)))];

console.log('a: ', a);
console.log('b: ', b);
console.log('c: ', c);
console.log('union(a, b): ', union(a, b));
console.log('union(a, c): ', union(a, c));
// union multiple arrays with the union function
console.log('union a b & c: ', [a, b, c].reduce((total, arr) => union(total, arr), []));

console.log('intersection(a, b): ', intersection(a, b));
console.log('minus(a, b): ', minus(a, b));
console.log('minus(b, a): ', minus(b, a));

// How to accept an arbitrage number of sets?
// Can implement with [arr1, arr2, arr3].reduce((result, item) => union(result, item), []);

// Flattening arrays
const nested1 = [ ['a'], [b, [1, 2]]];

const flatten = (arr) => arr.reduce((a, value) => a.concat(
  Array.isArray(value) ? flatten(value) : value
), []);

console.log('flattening: ', nested1);
console.log('result: ', flatten(nested1));

              
            
!
999px

Console