Beta

Typed Objects

Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • Voile Avatar
      it('Handles multiple reassignments', () => {
        const typed = typedObject({ a: Array, b: String, c: Set });
        const length = Object.keys(typed).length;
        
        Object.keys(typed).forEach((key) => {
          for (let i = 0; i <= length; i++) {
            typed[key] = i;
          }
        });
        
        assert.deepEqual(typed.a, [length]);
        assert.deepEqual(typed.b, `${length}`);
        assert.deepEqual(typed.c, new Set([length]))
      });
    

    This test in the test fixture assumes that every key is already set in the typed object before any assignment, which is different from the default behaviour of object (obviously, keys that are not set yet will not appear in Object.keys). This behaviour is not mentioned anywhere, and probably should be changed.

  • JohanWiltink Avatar

    a = b should return a ( with its new value ) in JS. The reference solution doesn't seem to do this and I haven't checked if this is tested. Existing programs sometimes rely on this; it is not good practice to return undefined for this expression even if the side effect is handled correctly.

  • JohanWiltink Avatar

    Consider describing the values in the configuration object as contructors ( because they, at least mostly, are ). And consider specifying untyped values by having their constructor be undefined ( that seems more appropriate than null ) instead of some arbitrary string instance.

    "you should use Array.of" is just wrong. You can, but there are other ( simpler ) methods as well. Especially given your estimated rank, I'd skip the whole tip and let solver figure it out.

  • JohanWiltink Avatar

    Actually, I like the concept.

    But not having random tests is an automatic downvote for me.

    Consider unpublishing the kata back to Draft while you add random tests.

  • JohanWiltink Avatar

    Description lacks actual specifications. Examples are not specifications.

    Description is also missing what the initial values in a new typeObject should be.

  • Shikiiii Avatar

    Is using code really the best way to explain this kata? :V I think it should have a(t least a) short description to explain what's going on.

  • FArekkusu Avatar

    No tests where a new value is set in the typed object.

    Edit: at least, I assume typedObject should support such behavior, otherwise why would the value be assigned instead of being provided as an additional function argument in the first place.

  • Blind4Basics Avatar

    Object.keys(typed).forEach((key) => (typed[key] = 1));

    this implies a lot of things and is never talked about in the description. Meaning the user cannot actually know what the task is by reading the desciption.

    cheers

  • FArekkusu Avatar

    No random tests. "I'll fix it later" is not a reason for resolving issues.

  • FArekkusu Avatar

    PascalCase is used for naming classes, for functions use camelCase.

  • FArekkusu Avatar

    The "non-typed" thing is not tested.

  • FArekkusu Avatar

    No random tests.