Ad
  • Custom User Avatar

    When you mutate the input, unexpected results could happen. I've changed the tests so it doesn't matter anymore, but keep that in mind.

  • Custom User Avatar

    That happened because you mutated the input in your code. Now it doesn't matter.

  • Default User Avatar

    because count is an object. the ternary operation is checkin if the property (key: value) is in the count object already. if yes, it adds 1 to the stored value, if not it sets/adds the property.

    so if string = 'example', the first run is going to see that count is empty, so count['e'] doesn't exist, and it will set count[e] = 1. then you have count = {e: 1}.