js solution implemented