This looks like the opposite of a singleton... Instead of always getting the same object by getInstance() here you always get a different one, but all share the same static counter value.
In the end, SingletonCounter is not actually used as a class, but rather as container for the counter variable, which could as well just be a global variable in this case.
I think the algorithm would be more effective (and easier to implement), if it wouldn't prioritize sequences of identical numbers over consecutive ones ;)
I guess that the random tests are run asynchronously. Since they all use the same variables vor queues1, queues2 and liftMax that could explain why the are always the same for every run. I'd try moving the code in the for-loop into the function passed to it().
I fixed this by clearing the original queue arrays in the queues array given to the function, though it wasn't necessary for my algorithm to produce the correct result.
But apparently the random test cases use the same queues array for each run and the sample solution clears it as well, logically producing the result [ 0 ] for every consecutive run (since there are no people wanting to go anywhere anymore).
This behavior of the random test runs seems buggy to me, though, and should be fixed!
All test pass for my solution (TypeScript) except "NotAllowedCharTests". It always reports expected [Function] to throw an error...
I definitely do execute throw new Error('Invalid character'); in that run, though. Did anyone else encounter this problem? Is a specific error expected?
To make the challenges more challenging for me I'm aiming for minimal code instead of product quality code ;)
true, there should be a test case for that
This comment is hidden because it contains spoiler information about the solution
Default test in TypeScript is broken: Missing
});
at the end.This looks like the opposite of a singleton... Instead of always getting the same object by
getInstance()
here you always get a different one, but all share the same staticcounter
value.In the end,
SingletonCounter
is not actually used as a class, but rather as container for thecounter
variable, which could as well just be a global variable in this case.This comment is hidden because it contains spoiler information about the solution
Johnny would get two exclamation marks here, but luckily, his case is apparantly not even tested ;)
Wouldn't this yield the wrong result, if
array[n] === 0
andn > 0
?Sample tests for TypeScript are broken:
I think the algorithm would be more effective (and easier to implement), if it wouldn't prioritize sequences of identical numbers over consecutive ones ;)
This comment is hidden because it contains spoiler information about the solution
I guess that the random tests are run asynchronously. Since they all use the same variables vor
queues1
,queues2
andliftMax
that could explain why the are always the same for every run. I'd try moving the code in thefor
-loop into the function passed toit()
.I guess the brackets won't work reliably if there are multiple of them, would them?
I fixed this by clearing the original queue arrays in the
queues
array given to the function, though it wasn't necessary for my algorithm to produce the correct result.But apparently the random test cases use the same
queues
array for each run and the sample solution clears it as well, logically producing the result[ 0 ]
for every consecutive run (since there are no people wanting to go anywhere anymore).This behavior of the random test runs seems buggy to me, though, and should be fixed!
All test pass for my solution (TypeScript) except "NotAllowedCharTests". It always reports
expected [Function] to throw an error
...I definitely do execute
throw new Error('Invalid character');
in that run, though. Did anyone else encounter this problem? Is a specific error expected?Loading more items...