Ad
  • Custom User Avatar

    I don't remember this kata at all, but I see lots of other similar solutions... I'm not sure how I came up with this.

  • Custom User Avatar

    Can you describe the solution?

  • Custom User Avatar

    The first one takes care of molecules like this: Cl2. What it does is repeat the molecule x times. So Cl2 becomes ClCl.
    The second one takes care of molecules with braces with a number after them. E.g. (CCHHHH)2 becomes CCHHHHCCHHHH. The third and fourth do the same but with [] and {} respectively.
    The fifth one removes all left over braces as all braces that are left are guaranteed to have no number after them (so no repeating needed anymore).
    The sixth one takes each atom and adds a space after it.
    Then all the atoms can be split by splitting on a space, after which the reduce counts theatoms.

    Its not fast but a funny one liner, though it is not perfect as nested braces don't seem to work (e.g. ((C2H6))2)

  • Custom User Avatar

    Can u explain reg exp ?

  • Custom User Avatar

    In start, store is not a number is undefined. Your store type should be number | undefined