day-1.mjs

December 25, 2021 ยท View on GitHub

/////////////////////////////////////////////////////////////////////////////// // Day 1 - Surviving the Freeze (Warmup) // // #region problem // /////////////////////////////////////////////////////////////////////////////// // Write the bodies to setData and getData below so that the assert doesn't // // throw an Error. // ///////////////////////////////////////////////////////////////////////////////

/**

  • Assign some value to object so it can be
  • retrieved later
  • @param {Readonly} object
  • @param {any} value
  • @returns {void} */ let setData = (object, value) => { // ... }
  • /**

    • @param {Readonly} object
    • @returns {any} */ let getData = (object) => { // ... }
    • /////////////////////////////////////////////////////////////////////////////// // #endregion problem // ///////////////////////////////////////////////////////////////////////////////

      /////////////////////////////////////////////////////////////////////////////// // Test - Leave code after this alone // // #region test // ///////////////////////////////////////////////////////////////////////////////

      import assert from 'node:assert/strict';

      /**

      • @type {Readonly<{}>} */ const object = Object.freeze(Object.create(null));

      setData(object, 'On the first day of christmas'); // make this print the value given to setData(object, value); above const result = getData(object) console.log(result); assert.strictEqual(result, 'On the first day of christmas');

      /////////////////////////////////////////////////////////////////////////////// // #endregion test // ///////////////////////////////////////////////////////////////////////////////

      /////////////////////////////////////////////////////////////////////////////// // Hints - Encoded in ROT13 encoded // // #region hints // /////////////////////////////////////////////////////////////////////////////// // // // Fvzcyr: Znc / JrnxZnc pbhyq qb vg. // // // // // // Nqinaprq: pynff cevingr svryqf pna or nqqrq gb sebmra bowrpgf: // // uggcf://tvfg.tvguho.pbz/ozrpx/3955r617or395094432s4n3prno23qr7 // // // /////////////////////////////////////////////////////////////////////////////// // #endregion hints // ///////////////////////////////////////////////////////////////////////////////

      /////////////////////////////////////////////////////////////////////////////// // Use Cases // // #region uses // /////////////////////////////////////////////////////////////////////////////// // // // This kind of workflow can help when you are given immutable an object & // // want to keep data associated with the object. Take care to use things // // that don't keep the object alive if you want the associated data to GC // // the object. // // // /////////////////////////////////////////////////////////////////////////////// // #endregion uses // ///////////////////////////////////////////////////////////////////////////////