"numeric palindromes" is rather unfortunate term. It is not clear if nonintegers are to be considered. The implementation only considers integers, in which case i would rather use term "palindromic integers".
It is also not explicitly stated, although assumed, that only base 10 representations are to be considered. Some numbers that are not palindromic in base 10 may be palindromic in different bases. I would actualy say that every nonnegative integer is palindromic in infinte amount of various bases. And so even a better term might be "palindromic base 10 integers".
preferably without using a for loop
That is a silly requirement, you could do it with
reduce but that would require to first create an array of all the numbers less then n. Which would increase the memory complexity of the implementation to
O(n) for no real benefit. And it will probably be slower, although the big-O time complexity stays the same.
To be complete the current memory complexity Is
O(log(n)). And time complexity is
O(n * log(n)), or more precisely
Since you are not asking to improve performance, but rather to shorten the code (and that's perfectly fine if you dont pass large n's and dont call the function many times in a loop) , I would say you are pretty good with your current implementation.
I would just replace the ternary with an
if because adding zero is a useless operation.
And there is a bug in your implementation where the result is by 1 greater then it should be if the input n is a palindrome. You should do
i < n instead of
i <= n.
If you want to improve the time complexity, you need to do some maths as @vnp already suggested. Intuition tells me you might end up with time complexity
O(log(n)) and that will be a big improvement for bigger n's compared to your current