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.


                <h2>Flatten Dictionary</h2>
<i>Generic dictionary flattening algorithm</i></br>
<i>(Didn't write this as quickly as I wanted during practice)</i></br>
<div id="first"></div>
<div id="second"></div>
<div id="third"></div>




                const out = (msg, context) => {
  const out = JSON.stringify(msg)
  const br = document.createElement("br")
  const el = document.getElementById(context)
  const tn = document.createTextNode(out)

/** BEGIN Flatten Dict - allows deeply nested objects to be be presented as a depth one object */
const flattenDictionary = (dict, context) => {
  let result = {}

  // Helpers
  const isNotDeep = obj => typeof obj === "string" || typeof obj === "number"
  const isEmt = str => str === ""
  const keyHelper = (trail, current, deep) => trail === "DEFAULT" ? current : deep ? trail + "." + current : current
  const recurse = (dict, key, result, deep) => {
    const currentKeys = Object.keys(dict)
    for (let i = 0; i < currentKeys.length; i++) {
      let currentKey = currentKeys[i],
        currentVal = dict[currentKey],
        oldKey = key
      key = keyHelper(key, currentKey, deep)
      if (isNotDeep(dict[currentKey])) {
        result[key] = dict[currentKey]
        key = oldKey
      } else recurse(currentVal, key, result, true)
  recurse(dict, "DEFAULT", result, false)
  out(result, context)
/** END Flatten Dict - allows deeply nested objects to be be presented as a depth one object */

var dictOne = { a: { b: 2, c: { d: 34, e: 31 } }, f: 5 }
flattenDictionary(dictOne, "first")

var dictTwo = { a: { b: 2 }, c: 5, d: { e: 65, f: 233 } }
flattenDictionary(dictTwo, "second")

var dictThree = { a: { b: 2, c: 100 }, d: 1, e: { f: 99, g: 1000 } }
flattenDictionary(dictThree, "third")