A more useful property of this can be seen when using functions like map, e.g. [1,2,3].map(x => String(x)) can be shortened to just [1,2,3].map(String)
[1,2,3].map(x => String(x))
This is amazing solution
Great onee liner.
Well replace would reduce the number of characters before the split, resulting in a shorter array for filter to spin through. Since each array element is a string, then fewer String objects are created.
I found a resource that explains __builtin_popcount and shows other useful builtin functions of GCC compiler.
For those interested, link below :)
as said by David Vandevoorde on Quora:
"it is available in GCC, Clang, and EDG."
For clarity I link the full answer: https://www.quora.com/What-is-__builtin_popcount-in-c++
I hope I was helpful :)
Reported on github.
Sorting just to take the min or max is inefficient. This is O(n log n) instead of O(n).
True that it is negligible but since they asked: the ternary is more efficient.
In general, operators are ever so slightly faster than function calls.
but They did not ask to change the current string , if they wnat to change it then there is no need for reterned
value .. other wize is to create a new string make a change of it and return a copy of it ..
you also don't need to check for even numbers (except 2)
This is why I love codewars! I never would have found about about this.
Does this only work with GNU compilers?
good time complexity on this one, think it's optimal
Uh, is that legal? ))
The point of the task is to use RegExp.