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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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.







const object1 = {
  a: { x: 1 }, 
  b: [2, 3],
  c: 4,
  d: { e: "5", f: null },

const object2 = {
  a: { x: 1 },
  b: [2, 3],
  c: 4,
  d: { e: "5", f: null },

// Solution #1: Very dirty, quick solution
// I wouldn't use but good to mention on an interview first
function isEqual(obj1, obj2) {
  const a = JSON.stringify(obj1);
  const b = JSON.stringify(obj2);
  // sort so it will take an account for property that is not in order
  return a.split("").sort().join("") == b.split("").sort().join("");

console.log("Solution #1:", isEqual(object1, object2));

// Solution #2: Custom, recursive solution
// Might be the one that interviewer wants
function deepEqual(obj1, obj2) {
  // ensure that arguments are objects then recurse through one by one
  return obj1 && obj2 && typeof obj1 === "object" && typeof obj2 === "object"
    ? // return false right away if objects properties length are not equal
      Object.keys(obj1).length === Object.keys(obj2).length &&
        // use reduce setting the initial value to equal which is true
        Object.keys(obj1).reduce((prev, curr) => {
          // then recurse as deep as possible and keep recursing if values are objects
          return prev && deepEqual(obj1[curr], obj2[curr]);
        }, true)
    : // just do normal compare
      obj1 === obj2;

console.log("Solution #2:", deepEqual(object1, object2));

// Solution #3: For production code that I recommended
// Using Lodash Deep Equal
// I would argue that this is the best as it is fully tested and used by the FE community. Sure, it may add slight overhead but for what it is worth, we are paying for something that is stable and great.
function lodashEqual(obj1, obj2) {
  return _.isEqual(obj1, obj2);

console.log("Solution #3:", lodashEqual(object1, object2));