Ad
  • Custom User Avatar

    Thank you very much for your reply ;)

  • Default User Avatar

    It's a bitwise OR operator which in this case (against 0) essentially cuts of all non integers. Here it's used as a somewhat crude and hacky way to avoid Math.floor() or parseInt().

    My advise would be to be careful using it in your projects. The | 0 is easily overlooked and can leave your future you searching forever where your math doesn't add up. Math.floor() does a better job at being self-explanatory. Since the example above is very short, the | 0 doesn't hurt for the simple purpose it serves.

    Also look at stanleyvarga's comment. He also makes a solid point not to use it everywhere.

  • Custom User Avatar

    What means this "|" in Javascript ?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    And how are you adding all the numbers between a and b like that? See the last example, your code returns 1. The tests are ok, it's your code what's wrong.

    Given two integers a and b, which can be positive or negative, find the sum of all the numbers between including them too and return it. If the two numbers are equal return a or b.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution