<reponame>Joyang0419/linebot-ig<filename>07-Curriculum-Resources/whiteboard/3-Interview-Qs/1-Interview-Questions/scope_and_closure/Solved/solved.js<gh_stars>0'use strict';

function foo () {
  var updated = 0;
  var obj = {};

  var bar = function (arg) {
    var key = JSON.stringify(arg);

    if (!(obj[key])) {
      obj[key] = arg
      updated += 1;
    }

    console.log("You've updated the object " + updated + " times.");
    return obj[key];
  }

  return bar;
}
