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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <h1 id="naive">Not started naive</h1>
<h1 id="smarter">Not started smarter</h1>
<h1 id="equal">Not started equality check</h1>

              
            
!

CSS

              
                
              
            
!

JS

              
                // Pre-experiment setup
const vocationObjectList = [];
const nameObjectList = [];

const length = 25000;
for (let i = 0; i < length; i++) {
  vocationObjectList.push({ vocation: `Vocation ${i}`, id: i });
  nameObjectList.push({ name: `Name ${length - i - 1}`, id: length - i - 1 });
}

function naive() {
  // Setup
  document.querySelector("#naive").innerHTML = "Running naive";
  const before = performance.now();

  // The work
  const mapped = vocationObjectList.map(personWithVocation => {
    // Lets find the name in the name object list.
    const personWithName = nameObjectList.find(
      nameObj => nameObj.id === personWithVocation.id
    );
    return { ...personWithVocation, ...personWithName };
  });

  // Print speed
  const after = performance.now();
  document.querySelector("#naive").innerHTML = `Naive took ${Math.round(
    after - before
  )} ms`;

  return mapped;
}

function smarter() {
  // Setup
  document.querySelector("#smarter").innerHTML = "Running smarter";
  const before = performance.now();

  // The work

  // We can save a lot of time by creating a faster lookup than `.find`.
  // Javascript object lookup is super fast, so that is suitable.
  const nameLookup = {};
  nameObjectList.forEach(personWithName => {
    nameLookup[personWithName.id] = personWithName;
  });

  const mapped = vocationObjectList.map(personWithVocation => {
    // Now we can find the name by using a faster lookup method than .find
    const personWithName = nameLookup[personWithVocation.id];
    return { ...personWithVocation, ...personWithName };
  });


  // Print speed
  const after = performance.now();
  document.querySelector("#smarter").innerHTML = `Smarter took ${Math.round(
    after - before
  )} ms`;
  return mapped;
}

const smarterResult = smarter();
const naiveResult = naive();

// Lets just make sure they both produced the same result
let equal = true;
for (let i = 0; i < length; i++) {
  if (
    smarterResult[i].name !== naiveResult[i].name ||
    smarterResult[i].vocation !== naiveResult[i].vocation ||
    smarterResult[i].id !== naiveResult[i].id
  ) {
    equal = false;
  }
}
document.querySelector("#equal").innerHTML = `Equality check: ${equal}`;

              
            
!
999px

Console