I wrote this solution the first time as an answer to a question on Stack Overflow.<p><a href="https://stackoverflow.com/a/50134728/755343" rel="nofollow">https://stackoverflow.com/a/50134728/755343</a>