You need to sign in or sign up before continuing.×
Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
yep, that's a first!
i dont see how an ad blocker could possibly interfere with the variables, the code is evaluated server side, not client side
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.
Very good use regular expression.
This is very clever, but how in the world is this a best practice? It's barelly readable!
Each a.shift is an O(n) operation. You're pretty much making 1 operation per each element of the array. This code is really short, but really inneficient :(.
n = [a, b, c, d, e];
n.shift();
This moves a out, moves b to 0, moves c to 1, moves d to 2... etc.
If your array is large enough, these operations add up.
Actually, this is still giving me problems:
ReferenceError: Value is not defined
at Test.it
at Test.describe
You should disable AdBlock... it was blocking the Value global from showing up in my environment.
I'm also getting this error. What's up with writting your own node class? This doesn't make any sense. You're supposed to get your node object as a parameter.
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.
It doesn't really matter to avoid a bucles because it would have a logarithmic number of iterations in the number of digits.
I might be wrong, but
(ops[operation] || function() {return null;})
seems to return a function fromops
object or a function that returnsnull
if no suchoperation
is defined. This is possible becauseops[operation]
returnsundefined
for unexistent members, which in turns forcesfunction () { return null; }
to be evaluated and returned.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.
Wow... got a bit lost in this line:
return (ops[operation] || function() { return null; })(num1, num2);
Anyone care to explain ?