day-7.mjs
December 31, 2021 ยท View on GitHub
///////////////////////////////////////////////////////////////////////////////
// Day 7 - Under the ice //
// #region problem //
///////////////////////////////////////////////////////////////////////////////
// Write a class Magic that returns instances that inherit with a //
// prototype of BASE, are instanceof Magic, are frozen, have no properties, //
// neither own nor inherited, and when calling the static method //
// Magic.set(obj, key) add properties that can be used to write and get via //
// magicInstance[key] and key in magicInstace returns true. //
///////////////////////////////////////////////////////////////////////////////
class Magic { // ... }
/////////////////////////////////////////////////////////////////////////////// // #endregion problem // ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// // Test - Leave code after this alone // // #region test // ///////////////////////////////////////////////////////////////////////////////
import assert from 'node:assert/strict';
function check(ctor) { let obj = new ctor(); assert.strictEqual(Object.isFrozen(obj), true); assert.strictEqual(obj instanceof ctor, true); assert.strictEqual('property' in obj, false); Magic.set(obj, 'property') assert.strictEqual('property' in obj, true); const value = obj.property = Symbol('i am a symbol'); assert.strictEqual(obj.property, value); } check(Magic); class SubMagic extends Magic { } check(SubMagic);
/////////////////////////////////////////////////////////////////////////////// // #endregion test // ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// // Hints - Encoded in ROT13 encoded // // #region hints // /////////////////////////////////////////////////////////////////////////////// // // // Fvzcyr: Sebmra bowrpgf ner bayl purpxrq sbe funyybj serrmvat. // // // /////////////////////////////////////////////////////////////////////////////// // #endregion hints // ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// // Use Cases // // #region uses // /////////////////////////////////////////////////////////////////////////////// // // // This is purely esoterica to my knowledge. // // // /////////////////////////////////////////////////////////////////////////////// // #endregion uses // ///////////////////////////////////////////////////////////////////////////////