Javascript solution for Problem 003