Javascript solution