Ad
  • Default User Avatar

    yep, that's a first!

  • Default User Avatar

    i dont see how an ad blocker could possibly interfere with the variables, the code is evaluated server side, not client side

  • Custom User Avatar

    That is not true.

    Array indices are based on some offset from the first address. A shift basically means setting a new first address.

    Of course, this is assuming a standard implementation of the array data structure. If you implemented an array with a stack, then it will obviously be O(n) instead of O(1).

    And if you really want to talk about worst case time complexities, a push could actually be an O(n) operation even for the standard implementation. It just depends on memory allocated.

  • Default User Avatar

    ops[operation] || function() { return null; }
    You need this function for other operation values beside "+-*/" and it would return null.
    For example, if you get "m" or "w" as an operation, the compiler will give errors since m or w are not a method so OR function is needed to return null.

  • Custom User Avatar

    I might be wrong, but (ops[operation] || function() {return null;}) seems to return a function from ops object or a function that returns null if no such operation is defined. This is possible because ops[operation] returns undefined for unexistent members, which in turns forces function () { return null; } to be evaluated and returned.

  • Custom User Avatar

    Basically, if the operation exists in the ops object I call its function with the num1 and num2 arguments.

    If the operation does not exist in ops I default (using ||) to a function which returns null. num1 and num2 are also provided to the default function but are ignored.