Are you actually using this in production code? 😂😂
You realise how inefficient this is right? 😂😂
I have adapted Namir's method (see comments). And it is probably the most efficient.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.