Added Javascript solution by Xelio.