JS Solution

Pretty simple JS solution.