New answers tagged

1

Well you're right to be concerned. Your example is essentially this function wrapCheck(check) { return { check, largeArr: Array(1000000) .fill(0) .map((_, i) => i), makeNew: function (pred) { return wrapCheck(() => check(this).filter(pred)); } ...


1

I have some suggestions to make the code cleaner, not faster. Always try to pass the size of the maximum size to the Collection / Map when known The ArrayList has a default size of 10 elements, if you have more elements, the list will have to resize its internal pool. By setting the size, you can prevent the resize and make your code faster. //[...] int ...


2

next(iterable, [ default ]) I find too many try-except block can be distracting. next() takes an optional second argument--a default value to return when the iteration finishes. Here is @Graipher's _morgan() function using the 2-argument form of next() instead of try-except. def _morgan(a, b): a = iter(a) x = next(a, None) b = iter(b) y =...


2

There is no need to read the whole string into a deque. Just iterate over the strings using iterators. The only gotcha is handling the fact that either of the strings can be empty at the beginning and that one can be exhausted before the other. def _morgan(a, b): a, b = iter(a), iter(b) try: x = next(a) except StopIteration: ...


Top 50 recent answers are included