working js solution