Pen Settings



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


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


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.


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.






                function mergeChildMappings(prev, next) {
  prev = prev || {};
  next = next || {};

  function getValueForKey(key) {
    if (next.hasOwnProperty(key)) {
      return next[key];

    return prev[key];

  // For each key of `next`, the list of keys to insert before that key in
  // the combined list
  let nextKeysPending = {};

  let pendingKeys = [];
  for (let prevKey in prev) {
    if (next.hasOwnProperty(prevKey)) {
      console.log('next does have key ', prevKey)
      if (pendingKeys.length) {
        console.log('added to nextKeysPending: ', pendingKeys);
        nextKeysPending[prevKey] = pendingKeys;
        pendingKeys = [];
    } else {
      console.log("next doesn't have key ", prevKey);
      console.log('adding ', prevKey, ' to pendingKeys, which is currently', pendingKeys);
  console.log('pendingKeys: ', nextKeysPending);

  let i;
  let childMapping = {};
  for (let nextKey in next) {
    if (nextKeysPending.hasOwnProperty(nextKey)) {
      console.log('nextKeysPending does have key ', nextKey);
      for (i = 0; i < nextKeysPending[nextKey].length; i++) {
        let pendingNextKey = nextKeysPending[nextKey][i];
        console.log('giving key', nextKeysPending[nextKey][i], ' value of ', getValueForKey(
        childMapping[nextKeysPending[nextKey][i]] = getValueForKey(
    console.log('giving key', nextKey, ' value of ', getValueForKey(nextKey));
    childMapping[nextKey] = getValueForKey(nextKey);

  // Finally, add the keys which didn't appear before any key in `next`
  for (i = 0; i < pendingKeys.length; i++) {
    childMapping[pendingKeys[i]] = getValueForKey(pendingKeys[i]);

  return childMapping;

const prev = {
  'key-2': 'child 2',
  'key-1': 'child 1', 
  'key-5': 'child 3', 
  'key-7': 'child 7',
  'key-8': 'child 8',
const next = {
  'key-1': 'child 1',
  'key-3': 'child 3',
  'key-6': 'child 6',
  'key-7': 'child 7',
  'key-9': 'child 9',
console.log(Object.keys(mergeChildMappings(prev, next)))